Using ArcPy with Anaconda

Recently I have had really good luck using Anaconda to manage Python modules, but I didn’t know how to use the ArcGIS 10.2 ArcPy module with it.  ArcGIS installs its own Python installation (C:\Python27\ArcGIS10.2) and I was only able to import arcpy when using the this copy of Python.

To make this work, I started with this really helpful stackoverflow post.  Basically, I uninstalled all existing ArcGIS installations and python modules, installed ArcGIS, then installed Anaconda (or Miniconda) using all the default settings/options.  I clicked the button to register Anaconda as the default Python installation, but I’m not sure this actually worked.

Unlike the stackoverflow poast, I then added C:\Anaconda and C:\Anaconda\bin to the system path, but I removed C:\Python27\ArcGIS10.2.  For ArcGIS 10.2 (32bit), the file in C:\Python27\ArcGIS10.2\Lib\site-packages that you need to copy to C:\Anaconda\Lib\site-packages is called desktop10.2.pth.  For ArcGIS 10.2 (64bit), the file in C:\Python27\ArcGISx6410.2\Lib\site-packages that you need to copy to C:\Anaconda\Lib\site-packages is called DTBGGP64.pth.

Finally, the only way I could get the Anaconda Python to be used when double clicking on a .py file was to modify the registry.  I didn’t try it but you could probably change these values from the command prompt as outlined in the Python documentation.  I changed the following keys to point to the Anaconda folder:

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.File\shell\Edit with IDLE
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.File\shell\open
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Python.CompiledFile\shell\open\command

After that I could import ArcPy from the Anaconda Python without error.

1 thought on “Using ArcPy with Anaconda

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s