Skip to main content
Solved

Best way to use ArcPy without changing the python interpreter


Forum|alt.badge.img

Hi

Any idea of the best method for using the Arcpy library without changing the interpreter to ESRI?

Thanks

Best answer by david_r

It is theoretically possible, but the Python interpreter defined in FME Server needs to be identical to the one used by ArcGIS, if not there's a very good chance it won't work at all.

The trick is to set the PythonPath exactly like the one used by the ArcGIS Python interpreter. To find these paths, open the ArcGIS Python interpreter and type:

import sys
for x in sys.path:
    print x

This will dump all the entries in the PythonPath used by ArcGIS, and you can copy those into the non-ArcGIS Python interpreter before loading the arcpy module. Here are the values from my installation, you will have to use your own paths, of course:

import sys
sys.path=[]
sys.path.append(r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\ArcGIS\Python 2.7')
sys.path.append(r'C:\Python27\ArcGISx6410.2\DLLs')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib\plat-win')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib\lib-tk')
sys.path.append(r'C:\Python27\ArcGISx6410.2')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib\site-packages')
sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\bin64')
sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy')
sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Scripts')
import arcpy

Let us know how it works for you.

David

View original
Did this help you find an answer to your question?

6 replies

david_r
Evangelist
  • March 24, 2016

Hi

Why can't you change the Python interpreter? It's pretty trivial.

David


Forum|alt.badge.img
  • Author
  • March 24, 2016

I will probably have to roll out a workbench to FME Server and even though its a small change to a file config, it will be a huge change process here so its easier if i can call it externally to ESRI's interpreter as FME Server is setup to look at the default interpreter.


david_r
Evangelist
  • Best Answer
  • March 24, 2016

It is theoretically possible, but the Python interpreter defined in FME Server needs to be identical to the one used by ArcGIS, if not there's a very good chance it won't work at all.

The trick is to set the PythonPath exactly like the one used by the ArcGIS Python interpreter. To find these paths, open the ArcGIS Python interpreter and type:

import sys
for x in sys.path:
    print x

This will dump all the entries in the PythonPath used by ArcGIS, and you can copy those into the non-ArcGIS Python interpreter before loading the arcpy module. Here are the values from my installation, you will have to use your own paths, of course:

import sys
sys.path=[]
sys.path.append(r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\ArcGIS\Python 2.7')
sys.path.append(r'C:\Python27\ArcGISx6410.2\DLLs')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib\plat-win')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib\lib-tk')
sys.path.append(r'C:\Python27\ArcGISx6410.2')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib\site-packages')
sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\bin64')
sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy')
sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Scripts')
import arcpy

Let us know how it works for you.

David


Forum|alt.badge.img
  • Author
  • March 24, 2016

cheers, thats spot on!


ngoorman
Contributor
Forum|alt.badge.img+3
  • Contributor
  • January 26, 2017
david_r wrote:

It is theoretically possible, but the Python interpreter defined in FME Server needs to be identical to the one used by ArcGIS, if not there's a very good chance it won't work at all.

The trick is to set the PythonPath exactly like the one used by the ArcGIS Python interpreter. To find these paths, open the ArcGIS Python interpreter and type:

import sys
for x in sys.path:
    print x

This will dump all the entries in the PythonPath used by ArcGIS, and you can copy those into the non-ArcGIS Python interpreter before loading the arcpy module. Here are the values from my installation, you will have to use your own paths, of course:

import sys
sys.path=[]
sys.path.append(r'C:\ProgramData\Microsoft\Windows\Start Menu\Programs\ArcGIS\Python 2.7')
sys.path.append(r'C:\Python27\ArcGISx6410.2\DLLs')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib\plat-win')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib\lib-tk')
sys.path.append(r'C:\Python27\ArcGISx6410.2')
sys.path.append(r'C:\Python27\ArcGISx6410.2\lib\site-packages')
sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\bin64')
sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy')
sys.path.append(r'C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Scripts')
import arcpy

Let us know how it works for you.

David

sys.env is incorrect; it should be sys.path

 


david_r
Evangelist
  • January 26, 2017
ngoorman wrote:
sys.env is incorrect; it should be sys.path

 

Yes, you're absolutely right, thanks for pointing it out. Fixed.

 

 


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings