Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing arcpy module into anaconda's Spyder

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?

like image 510
user2657663 Avatar asked Nov 05 '13 17:11

user2657663


People also ask

Can you run Arcpy on Mac?

Both ArcMap and ArcGIS Pro are programs designed to run on the Windows operating system (OS). These software do not run natively on a Mac, and require that you install and set up Windows OS on your computer.

How do I add Arcpy code to Visual Studio?

In VS Code select the Python Interpreter. Hit Ctrl-Shift-P then select option Python: Select Interpreter. The name of the cloned active environment is C:\mypath\arcgispro-env. So select this in VS Code and it is now linked in to the same python environment used by ArcGIS Pro.


2 Answers

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.

like image 154
Carlos Cordoba Avatar answered Sep 21 '22 10:09

Carlos Cordoba


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.

like image 23
WxCZar Avatar answered Sep 21 '22 10:09

WxCZar