I'm trying to use ArcPy in PyScripter. I don't have admin privileges on this computer (it's my work computer) so I have to use a portable version of PyScripter. I'm sure my boss would let me install it, but I'd rather not bother her about it unless I have to; I'd like to try to find a workaround first.
Initially, when I typed import arcpy
into PyScripter, I was getting the usual no module named arcpy
error. Then I followed the instructions listed on this site about accessing ArcPy from a portable edition of PyScripter.
I think I have my Python PATH set up correctly: it includes the paths to ArcGIS\Desktop10.3\arcpy, \bin, and \ArcToolbox\Scripts. But now, when I import arcpy
, I'm getting the following error:
Traceback (most recent call last):
File "<string>", line 301, in runcode
File "<interactive input>", line 1, in <module>
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\__init__.py", line 21, in <module>
from arcpy.geoprocessing import gp
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\geoprocessing\__init__.py", line 14, in <module>
from _base import *
ImportError: No module named '_base'
I'm wondering if there's some conflict between my PyScript paths, and the paths that ArcMap uses when running python? When I type os.__file_
into the Python interpreter in ArcMap, it reads 'C:\\Python27\\ArcGIS10.3\\Lib\\os.pyc'
. Is that not good…?
Most similar threads suggest that I uninstall/reinstall ArcMap to see if that helps, but again, that requires administrative approval and I'd like to hold off on that until I absolutely have to, because I'd like to solve this on my own first. Especially because there's no guarantee that will work.
I'm using ArcGIS Desktop 10.3 Advanced, and PyScripter 2.6.00 x64.
Best Answer
Ok, after seeing your python environment from the
sys.path
, it is definitely your anaconda install that has caused the problem. This isn't really a "problem" per se, just that when you run your Python IDEs they will default to the most recent version of Python you installed. So in your case, you installed ArcGIS at some point, then you installed Anaconda Python.So what happened was, the Anaconda version is now your default when you run your IDE standalone. The reason this works in ArcMap/Catalog's Python window is because the interpreter is pointing to the ArcGIS Python install
'C:\Python27\ArcGIS10.3\'
. I use PyScripter too, but am not sure how it is choosing the interpreter to use, but if I had to guess I would say it's using thePYTHONPATH
windows environment variable.When I print off
os.environ['PYTHONPATH']
, I get a list that looks like this:So, if you want to set your default
PYTHONPATH
back to what the ArcGIS environment is, you'll have to follow these steps:import sys
then get the list ofsys.path
. This should get you a list of the ArcGISPYTHONPATH
(doprint sys.path
so you do not get the double backslash in the paths\\
)PYTHONPATH
variable and set this to the ArcGIS sys.path from your clipboard. Hit OK. You'll need to do this as an Administrator.Next time you run PyScripter, I believe the interpreter should reference the ArcGIS Python install and you should not get an import error.