Geographic Information Systems Asked by model_help on August 24, 2021
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.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
python27Libsite-packages
folder 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 FilesArcGISDesktop10.2.2arcpy c:Program FilesArcGISDesktop10.2.2bin c:Program FilesArcGISDesktop10.2.2ArcToolboxScripts
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 python27Libsite-packages.
Correct answer by PolyGeo on August 24, 2021
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)
or
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.
Answered by Javad Koohpayma on August 24, 2021
@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:Python27ArcGIS10.3Libsite-packages
had a file called Desktop10.3.pth
in it with the following lines:
C:Program Files (x86)ArcGISDesktop10.3bin
C:Program Files (x86)ArcGISDesktop10.3ArcPy
C:Program Files (x86)ArcGISDesktop10.3ArcToolBoxScripts
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:
Navigate to C:Python27
. You should see a folder called ArcGIS10.3
or whichever version you have installed.
Click into 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:Python27ArcGIS10.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!
Answered by Blairg23 on August 24, 2021
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:Python27ArcGIS10.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.
Answered by Prottoy on August 24, 2021
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 FilesArcGISProbinPythonScripts
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
.
Answered by Amber Keller on August 24, 2021
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!
Answered by Gijs on August 24, 2021
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)ArcGISDesktop10.3ArcPy' with a lowercase 'a' to match the destination path
Answered by Ant on August 24, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP