Select to view content in your preferred language

trouble importing arcpy or arcgisscripting in IDLE

2342
5
03-03-2010 06:47 AM
JonathanBoright
Emerging Contributor
An easy question here...

I've been using IDLE to run geoprocessing python scripts in previous versions of Arc, and I'l like to continue to do so... but I can't seem to import arcpy, or for that matter even arcgisscripting... I can get at them from the python window within ArcGIS (nice addition BTW!) 

What am I missing?

J
0 Kudos
5 Replies
JasonScheirer
Esri Alum
Are you sure you're running the IDLE from Python 2.6 and not Python 2.5?

Try this in the interactive prompt in IDLE:

>>> import sys
>>> sys.version
'2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)]'

You should get something that looks like "2.6.~~~~~~~"

Further troubleshooting (after issuing the first commands):

>>> sys.path

You should get back a list of directories. The directory for the arcgis desktop install should be there (something like C:\~~~~\ArcGIS\bin) -- if it's missing then Python's import path for ArcGIS has somehow been configured wrong.
0 Kudos
JonathanBoright
Emerging Contributor
thanks for the reply jscheirer,

I am definitely running 2.6... sys.version is:
'2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit (Intel)]'

however, I am running it on a 64-bit Windows 7 machine... perhaps that is my problem?

I think that you are on the right track with the second part of your response... sys.path has no ArcMap references in it...:
['C:\\Python26\\Lib\\idlelib', 'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs', 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk', 'C:\\Python26', 'C:\\Python26\\lib\\site-packages']

...whereas my ArcGIS bin directory is in C:\Program Files (x86)\ArcGIS\Desktop9.4\bin...  (this is the directory where 32-bit programs are installed). I *have* added the ArcGIS bin to my PATH environmental variable... to no avail...

So... how do I configure my Python import path correctly?

Thanks again!

J
0 Kudos
JasonScheirer
Esri Alum
The ArcGIS installer should have created a file called C:\Python26\Lib\site-packages\Desktop10.pth that adds the ArcGIS install to Python's path. You can manually recreate it. It's a text file with a list of paths on each line. You just need to open up notepad and enter the following:

C:\Program Files (x86)\ArcGIS\Desktop9.4\bin
C:\Program Files (x86)\ArcGIS\Desktop9.4\arcpy

and save it as C:\Python26\Lib\site-packages\Desktop10.pth. Then you should be good to go.
0 Kudos
JonathanBoright
Emerging Contributor
Great! that did the trick. Thanks!
0 Kudos
MiguelLeon
New Contributor
I seemed to have to add c:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy to my Desktop10.pth before it would work. Not sure why.
0 Kudos