Importing arcpy module into anaconda's Spyder

user2657663 picture user2657663 · Nov 5, 2013 · Viewed 17.4k times · Source

I would like to use arcpy into Anaconda's Spyder. I have a full ArcGIS license, so this is not an issue. I am able to semi-import the module by way of copying the the arcpy folder out of C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy and into C:\Anaconda\Lib\site-packages, but the import is never completed because I get an error of "ImportError: No module named arcgisscripting". Is there any way for arcpy to work in Spyder?

Answer

Carlos Cordoba picture Carlos Cordoba · Nov 6, 2013

This is what you need to do:

  1. Open the Python window in ArcGIS, as described here

  2. In there run these two commands:

    import sys

    sys.executable

  3. Copy the output of the last command

  4. Open Spyder and go to

    Tools > Preferences > Python interpreter

    Select the option

    Use the following Python interpreter

    and paste there the result of step 3.

  5. Finally go to Consoles > Open an IPython console. This will open a new console that will be running the same Python version that comes with ArcGIS but inside Spyder. So you could run there whatever command you can run in ArcGIS Python Window.

Note: It is possible that this doesn't work if the Python that comes with ArcGIS doesn't have the ipykernel package.