7

I can't import arcpy in spyder but I don't have any problem when using PyScripter. The error that I get is:

ImportError: No module named 'arcpy'

I would prefer using Spyder, if I can solve this, any suggestions?

3
  • 1
    did you try going to options/settings ( i don't know what it is named for spyder, I use Pycharm) and setting the path to your arcpy? it looks like your interpreter is not finding where arcpy is located.
    – yanes
    Jan 14, 2016 at 17:27
  • 2
    If it is of any use to future readers I created a simple step by step guide for installing spyder for ArcPro which installs a version that is arcpy aware.
    – Hornbydd
    Nov 14, 2019 at 12:18
  • @Hornbydd great resource! thanks!
    – nate-m
    Dec 15, 2020 at 19:32

3 Answers 3

6

It's likely that your Spyder installation is using its own installed Python, whereas Arcpy will probably be bundled with your system installation or ArcGIS version.

You can change this by setting the path to your desired Python as Yanes mentioned above, see https://stackoverflow.com/questions/11919615/how-to-change-the-path-of-python-in-spyder. Go to preferences-> console->advanced settings, and set the path there. Your ArcPy path on Windows is likely to be something like 'C:\Python27\ArcGIS10.1' depending on your version.

5
  • I am using ArcGIS 10.3 and this procedure returns an "invalid file path" error message. I am using C:\Python27\ArcGIS10.3 as path.
    – FaCoffee
    Jan 9, 2017 at 12:49
  • @CF84 my guess is that your Python is installed elsewhere? See if you can locate it in then update the path accordingly.
    – Dùn Caan
    Jan 9, 2017 at 13:01
  • I in fact have two Python versions - one associated with Anaconda and the other with ArcGIS. How to deal with this? Never done before :)
    – FaCoffee
    Jan 9, 2017 at 13:04
  • Thats what the original question was about.. You can either change the version used by Spyder (as above), or copy/install the required libraries into the Spyder version. Arcpy etc will be located in something like 'C:\Python27\ArcGIS10.4\Lib\site-packages', copy it across to your Spyder folder (something like 'C:\Program Files (x86)\Anaconda2\Lib\site-packages', or add the ArcGIS version to your pythonpath i.e. stackoverflow.com/questions/3701646/…
    – Dùn Caan
    Jan 9, 2017 at 13:16
  • Thanks -- that helps. For the record, here in June 2018, running the current Spyder 3.2.8, the path to tab on which you can set the path to python is "Tools" -> "Preferences" -> "Python interpreter" -> "Use the following interpreter". Jun 29, 2018 at 19:04
1

This method worked for me to install ArcPy on Spyder. I am using ArcGIS Pro.

First, open Spyder and press: shift+ctrl+alt+P to open Preferences, then go to Python interpreter, select ‘use the following Python interpreter’ and enter the path to the Python folder in ArcGIS Pro. My path looks like this: C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe

Restart Spyder. The console may now be broken.

To fix this you need to go to the start menu in windows and type ‘Python Command Prompt’, right click on Python Command Prompt and choose ‘go to location’. Once in the folder with the Python Command Prompt, right click on the Python Command Prompt and choose ‘run as administrator’.

The Python Command Prompt will now open. Into the command prompt you need to type: pip install ipykernel cloudpickle

This should run its course. Once it is finished, restart Spyder and use ArcPy!

1
  • This is an answer for using ArcPy with ArcGIS Pro when the question is about using ArcPy with ArcMap.
    – PolyGeo
    Jan 11, 2022 at 4:19
1

You could clone ArcGispro conda like below:

conda creat --name arcgispro --clone="C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3"

Then, you could activate this conda env and install spyder on it. conda activate arcgispro conda install spyder

2
  • Simple and straightforward. Been scouring the internet for this answer! Thanks for the help!
    – nate-m
    Dec 15, 2020 at 19:31
  • This looks like an answer for using ArcPy with ArcGIS Pro when the question is about using ArcPy with ArcMap.
    – PolyGeo
    Jan 11, 2022 at 4:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.