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.
This error is discussed near the bottom of the Importing ArcPy documentation page where there are some additional notes about ArcGIS 10.2.1 (if that is the precise version that you are using).
@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.
My solve was rather brutal I recently installed ArcGIS10.5, but the system still included a ArcGIS10.2 python folder to which everything was directed. Removing those folders and re-installing my Python IDE (pyscripter) solved the issue!
I had the .pth file as described by Blairg23. I finally resolved the problem by replacing the upper case 'A' in the line 'C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy' with a lowercase 'a' to match the destination path