I have written a script and am trying to run it in Python IDLE 2.7.6.
I first try to
import arcpy, but I get an error message saying:
ImportError: No module named arcpy
Why does it not work?
I am using ArcGIS Desktop 10.2.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
This error is discussed near the bottom of the Importing ArcPy documentation page where there are some additional notes about ArcGIS 10.2.x (if that is the version that you are using):
Tip: If importing ArcPy produces either of the following errors, the required modules could not be found:
- ImportError: No module named arcpy
- ImportError: No module named arcgisscripting
To address this, browse using Windows Explorer to the
python27\Lib\site-packagesfolder and add or edit the Desktop10.2.2.pth file. The file should contain the three lines shown below (corrected to your system's path if they do not match):
c:\Program Files\ArcGIS\Desktop10.2.2\arcpy c:\Program Files\ArcGIS\Desktop10.2.2\bin c:\Program Files\ArcGIS\Desktop10.2.2\ArcToolbox\Scripts
From ArcGIS 10.3.x to 10.8.x (see Importing ArcPy for those versions) it looks like:
The installation will also add the file Desktop10.3.pth (or Engine10.3.pth or Server10.3.pth) into python27\Lib\site-packages.
@PolyGeo's solution is top-notch, but not perfect for every use case.
For example, in my use case, I had a Python 2.7.11 install on my machine and then I installed ArcGIS which came with Python 2.7.8. When I followed the instructions at Importing ArcPy, I found that the path
C:\Python27\ArcGIS10.3\Lib\site-packages had a file called
Desktop10.3.pth in it with the following lines:
C:\Program Files (x86)\ArcGIS\Desktop10.3\bin C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcToolBox\Scripts
Yet, I still could not get ArcPy to import w/o error. I found that this is because the Python path being used by my machine is the 2.7.11 path, rather than the 2.7.8 path (the ArcGIS-specific Python install). Even if you include the correct path inside your Windows Environment Variables, it will not work because when you type
python into the Command Line Interface, Windows does not know which Python install to use.
This is my work-around:
C:\Python27. You should see a folder called
ArcGIS10.3 or whichever version you have installed.
ArcGIS10.3 and locate the Python.exe executable. Copy/paste this exe and rename it
arcpy or something else that you can remember.
Make sure you have added the
C:\Python27\ArcGIS10.3 directory into your path in your Windows Environment Variables.
Open a new
cmd and type the name you used (i.e.
arcpy). You should see a Python interpreter open up and you should see the correct version 2.7.8. If this is all correct, try typing
import arcpy into the interpreter. If it works, you have been successful!
This problem happens for me because the path of
ArcGIS was in
Program File(x86) instead of normal place(program file). there are two methods to fix the problem:
you can change the path of python for example by
PyScripter (it has a function to change the path)
the easiest way is:
change the name of python27's folder to python27_old. in control panel click on
program and feature, choose
uninstall/change and repair
ArcGIS. it will install python again with correct path. It worked for me.
I had a similar problem, and had tried all the suggested solutions on this page (and others) in vain. The problem was that 'C:\Python27' was listed above 'C:\Python27\ArcGIS10.4' under PATH in Environment Variables. It was resolved once I switched the order of the two, so now any python execution first goes through the python.exe file inside the ArcGIS10.4 sub-directory. I hope this helps.
I just got off the phone with esri and the issue for me was resolved by launching jupyter notebook from the
proenv.bat file which is a command line space. k This file is located at
C:\Program Files\ArcGIS\Pro\bin\Python\Scripts On the proevn.bat file right click> Run as Administrator. Then you can launch jupyter notebook by typing jupyter notebook. Make sure you are in the correct file path space before typing jupyter notebook to launch it.
Note this is assuming you have jupyter installed by running
conda install ipython-notebook.