Importing arcpy module into anaconda's Spyder
Asked Answered
N

3

6

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?

Nickolasnickolaus answered 5/11, 2013 at 17:50 Comment(0)
T
5

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.

Teutonism answered 6/11, 2013 at 13:24 Comment(10)
This appears to crash Spyder once you select the ArcMap.exe. from step 3.Appomattox
@Borealis, that shouldn't be the output you get from Step 3. It should be a file ended in python.exeTeutonism
This works for me but you have to run the commands of Step 2 in the Idle console and not in the python window in ArcGis.Tevet
I don't understand how to execute step 5 on Spyder 2.3.8 and python 3.5. When executing ANY code I get: ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote hostPoliard
Where is the interpreters option? Is there one for macPentheus
I don't know how this is the accepted answer. It simply doesn't work for me. Step 2 doesn't return what you suggested, and there is no Interpreters menu. It is Preferences > Python interpreter to be specific.Robertaroberto
This answer was for the previous version of Spyder (i.e. Spyder 2.3). Let me update the answer for our latest version.Teutonism
In your note you mention that this doesn't work if the Python that comes with ArcGIS doesn't have the ipykernel package. If this is the case, how exactly do you fix this issue? Can a person simply copy the ipykernel package from the Anaconda install into the ArcGIS install?Suprasegmental
Nop, you need to install it into ArcGIS's Python using pip.Teutonism
this is not a working solution. The output of sys.executable is not a python environment when executed from from the arcgis pro python interpreter.Daumier
M
2

To address this, browse to the python27\Lib\site-packages folder, mine was located under "C:\Python27\ArcGIS10.1\Lib\site-packages", and find the file Desktop10.1.pth.

On my system, the problem was resolved by simply copying the Desktop10.1.pth file into "C:\AppData\Local\Continuum\Anaconda\Lib\site-packages".

If you are running Anaconda 64 bit, you will get a different error when you try to import arcpy because ArcGIS runs 32 bit. Therefore, you have to make sure that you have the Anaconda 32 bit installed rather than 64 bit so things match up with ArcGIS. Once the file is copied and you have Anaconda 32 bit, import arcpy should work.

Mapp answered 12/2, 2015 at 20:38 Comment(1)
ArcGIS 10.5 comes with 64-bit arcpy. In that case this same method works with 64-bit python, but you need to use the path under the folder for 64-bit ArcGIS installation. In my case it was C:\Python27\ArcGISx6410.5\Lib\site-packages\DTBGGP64.pthRobertaroberto
E
1

The only thing worked for me is: I just copied the arcpy folder from 'C:\Program Flies(x86)\ArcGIS\Desktop10.3' and pasted that into my '~Anaconda3\Lib\site-packages'. Now I can import arcpy into spyder of Anaconda3.

Evvoia answered 21/12, 2016 at 6:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.