1

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.

  • What does your sys.path say from PyScripter? Seems like there is something messed up in your Python environment. – crmackey Jan 20 '16 at 15:00
  • It's pretty lengthy, so here's a pastefile: pastebin.com/VdWiV0Dr . Maybe my Anaconda install is causing a problem? – ale19 Jan 20 '16 at 15:05
  • 2
    I may be mistaken, but I'm not sure ArcMap supports the x64 version of PyScripter. ArcPro will run 64 bit and Python 3.3, but ArcMap itself, at least, is 32 bit. You could also check if Python runs in the Python window within ArcMap, or in the version of Idle installed with Arc. – recurvata Jan 20 '16 at 15:41
  • I downloaded the 32 bit version of PyScripter and it works no! Didn't realize ArcMap was 32 bit. Thanks for your help. If you want to post your comment as an answer, I'll upvote and accept it! – ale19 Jan 20 '16 at 15:47
  • @cmackey 's answer may be the better one to upvote and accept. – recurvata Jan 20 '16 at 18:03
3

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 the PYTHONPATH windows environment variable.

When I print off os.environ['PYTHONPATH'], I get a list that looks like this:

'C:\Python27\ArcGIS10.3\Lib\idlelib;C:\Windows\system32\python27.zip;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;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'

So, if you want to set your default PYTHONPATH back to what the ArcGIS environment is, you'll have to follow these steps:

  1. Open ArcMap/Catalog and import sys then get the list of sys.path. This should get you a list of the ArcGIS PYTHONPATH (do print sys.path so you do not get the double backslash in the paths \\)
  2. Copy that list to the clipboard.
  3. If using Windows 7, go to your control panel>system>Advanced system settings. Click on the "Advanced" tab and click the Environment Variables button. Find the 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.