How to access Esri ArcPy modules from Enthought Canopy?

There is an easy way that doesn't involve messing with your system PATH or PYTHONPATH.

The Enthought Python Distributions, including Canopy x32, are stand-alone and don't need anything in the registry or in the environment variables. So they can play nice with other Python distributions like the one that comes with ArcGIS 10.1.

To access ArcGIS 10.1 python modules from Enthought Canopy: Create a "path" file in the Canopy user directory that points to the ArcGIS 10.1 python modules. On my system, I created a text file called arcpy.pth with these 4 lines:

# .pth file for arcpy
C:\ArcGIS\Desktop10.1\bin
C:\ArcGIS\Desktop10.1\arcpy
C:\ArcGIS\Desktop10.1\ArcToolbox\Scripts

and put arcpy.pth in the Canopy User site-packages directory:

C:\Users\rsignell\AppData\Local\Enthought\Canopy32\User\lib\site-packages

To access Enthought Canopy modules from ArcGIS 10.1: Create a "path" file in the Arc site-packages folder that points to the Canopy python modules. On my system, I created a text file called epd.pth with these 3 lines:

# .pth file for EPD Canopy
C:\Users\rsignell\AppData\Local\Enthought\Canopy32\User\Lib\site-packages
C:\Users\rsignell\AppData\Local\Enthought\Canopy32\System\Lib\site-packages

and then put epd.pth in the Arc site-package folder:

C:\Python27\ArcGIS10.1\Lib\site-packages

That's all I needed to do!

-Rich

P.S. This works because Enthought Canopy 1.0 and ArcGIS10.1 are at the same version of Python (2.7) and Numpy (1.6.1). I hope we can continue to have this compatibility!

Update: I just tried this with Canopy 1.0.3, which uses Numpy 1.7.1, and it still works, even though ArcGIS 10.1 is at Numpy 1.6.1. Hurray! Yippee!


Yes, it is. Here is an excerpt from an internal install guide that was just used to do the same on my machine (please make sure these apply to your particular machine):


Configure environment for EPD

  1. Add a new PATH in your user variables (prepend the epd to the PATH):

    (edit the paths below according to the version of EPD or ArcGIS you are using) PATH=C:\Python27_epd32;C:\Python27_epd32\Scripts;%PATH%

  2. If ArcGIS is installed, set the PYTHONPATH environment variable so
    ArcGIS can import EPD modules, and EPD can import ArcPy:

    PYTHONPATH= C:\Python27_epd32\lib\site-packages; C:\ArcGIS\Desktop10.1\bin; C:\ArcGIS\Desktop10.1\arcpy; C:\ArcGIS\Desktop10.1\ArcToolbox\Scripts

If you run into problems with ArcGIS conflicting with EPD, you can easily remove EPD from the ArcGIS environment by removing the references to EPD in the PYTHONPATH.


Disclaimer! While the steps below have worked for me in the past, I'm not a very DOS-savvy person and I'd feel better if you consulted someone in your IT department to make sure I'm not handing out poor advice. With that said, read on...

Adding paths to your environment variables is fairly straightforward using the DOS command prompt (All Programs > Accessories > Command Prompt). You will use the command setx to permanently alter your PATH and PYTHONPATH environment variables.

At the command prompt, type "echo %PATH%"; it will print out the string that is the PATH variable. It's essentially just a long string of characters. Now try it with the PYTHONPATH variable to see what's in that one. You'll notice each path in those variables is separated by a semi-colon (;). When we add new paths to these variables we must include these.

enter image description here

Essentially what you will be doing is telling the computer you want your new PATH and PYTHONPATH variables to equal some new string (path(s)) (like C:\Python27_epd32\lib\site-packages;C:\ArcGIS\Desktop10.1\bin;) plus what's already stored in the variable.

The command you will execute to set your PATH variable is: setx PATH=C:\Python27_epd32;C:\Python27_epd32\Scripts;%PATH% (make sure these paths are applicable to your system)

enter image description here

The command you will execute to set your PYTHONPATH variable is: setx PYTHONPATH=C:\Python27_epd32\lib\site-packages;C:\ArcGIS\Desktop10.1\bin;C:\ArcGIS\Desktop10.1\arcpy;C:\ArcGIS\Desktop10.1\ArcToolbox\Scripts;%PYTHONPATH% (make sure these paths are applicable to your system)

NOTE: Make sure that you add "%PATH%" and "%PYTHONPATH%" to the end of the respective commands. If you don't, you will be overwriting those variables with only the new paths and you will lose the current contents.