Skip to main content
Solved

Best way to use ArcPy without changing the python interpreter

  • March 24, 2016
  • 6 replies
  • 72 views

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

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

6 replies

david_r
Celebrity
  • 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
Celebrity
  • 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

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
Celebrity
  • January 26, 2017
sys.env is incorrect; it should be sys.path

 

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