Hello all,
I have been running into some configuration errors while trying to import arcpy module into a simple Python script file, and I suspect that the errors might have something to do with the environment variables settings. Prior to the error above, I was running into a "ImportError: No module named 'arcpy'" error, which was related to incorrect environment variables. I have both Python 2.7 and Python 3.4 installed on my computer, and I would like to be able to use both of them in my code, but I'm not sure if that's possible.
Operating System: Windows 7
Application: ArcGIS for Desktop version 10.2.1
Path to ArcGIS: C:\Program Files (x86)\ArcGIS\Desktop10.2
Path to Python 2.7: C:\Python27
Path to Python 3.4: C:\Python34
Python IDE: PyCharm Community Edition 4.5.1
Environment Variables:
PATH: C:\Python27\;C:\Python34\;D:\Documents and Settings\pkundu\AppData\Roaming\npm;C:\Program Files (x86)\Java\jre7\bin
PYTHONPATH: C:\Program Files (x86)\ArcGIS\Desktop10.2\bin;C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy;C:\Program Files (x86)\ArcGIS\Desktop10.2\ArcToolbox\Script
When I try to run a very basic command:
import arcpy
I get the following error:
Traceback (most recent call last):
File "D:/Documents and Settings/pkundu/Desktop/pytest/testpy2.py", line 6, in <module>
import arcpy
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\__init__.py", line 21, in <module>
from arcpy.geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
ImportError: No module named '_base'
Process finished with exit code 1
Would greatly appreciate a solution to this problem as I have not seen any other posts regarding this error. Most other posts have to do with the "ImportError: No module named 'arcpy'" error I was experiencing before I edited my environment variables to the ones listed above. When I followed the error code, I found that the geoprocessing folder contains both the "__init__.py" file and the "_base.py" file.
Solved! Go to Solution.
I resolved the problem by uninstalling Python 3.4.
I'm not sure if there's a workaround for also having Python 3.4 on your machine and running arcpy, but I wasn't able to get it to work for some reason.
That's kind of a shame. What if someone had other Python scripts already written in Python 3.4? Would they have to delete Python 3.4 and revert back to 2.7?
I don't understand your path, could you check..mine using ArcMap 10.3 which uses Python 2.7.x is
>>> import sys >>> sys.path ['', ...'C:\\Python27\\ArcGIS10.3\\DLLs', 'C:\\Python27\\ArcGIS10.3\\lib', 'C:\\Python27\\ArcGIS10.3\\lib\\plat-win', 'C:\\Python27\\ArcGIS10.3\\lib\\lib-tk', 'C:\\Python27\\ArcGIS10.3\\Lib\\site-packages\\pythonwin', # only for PythonWin 'C:\\Python27\\ArcGIS10.3', 'C:\\Python27\\ArcGIS10.3\\lib\\site-packages', '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', 'C:\\Python27\\ArcGIS10.3\\lib\\site-packages\\win32', 'C:\\Python27\\ArcGIS10.3\\lib\\site-packages\\win32\\lib'] >>>
Python 3.x is only used by ArcGIS Pro
What is that you need in 3.4? The differences are really not major with the exception of access to previously non-existent modules.
There was no specific reason other than wanting to get familiar with the newer Python version, but say if someone had other files already written in 3.4 before trying to run arcpy? Would they have to delete Python 3.4 in order to get arcpy to work?
I resolved the problem by uninstalling Python 3.4.
I'm not sure if there's a workaround for also having Python 3.4 on your machine and running arcpy, but I wasn't able to get it to work for some reason.
That's kind of a shame. What if someone had other Python scripts already written in Python 3.4? Would they have to delete Python 3.4 and revert back to 2.7?
No...you set up the paths properly and both can coexist nicely. But you solved your own problem, which is good.
Just wanted to share my problem and a fix.
We get quarterly update from our data provider, and the code is written in Python 2.7, and I really have not had the time to begin to convert 2.7 to 3.6 code.
I need part of the code to run in 3.6 because part of the data goes to our Google Cloud Storage. I separated this function and used subprocess.call("C:\Program Files\ArcGIS\Pro\bin\Python\Scripts\propy.bat", "file.py"]), and was getting the '_base' error.
In the file.py, when importing libraries, I imported sys and then removed all the paths to 2.7, then called arcpy:
import sys
listPath = sys.path
sys.path.remove(listPath[1])
sys.path.remove(listPath[1])
sys.path.remove(listPath[1])
import arcpy
I tried listPath.startswith("c:\\program files (x86)\\arcgis") but it didn't find all the 2.7 paths.
This will only delete the paths temporarily!