Schedule a script: ImportError: No module named arcpy

1866
5
06-06-2011 04:49 AM
deleted-user-VeZur_n9o0OZ
New Contributor III
Hi folks,

I've added a script to a toolbox that I'd like to run every X minutes as a scheduled task. If I try and run my .py file from command line I cannot import arcpy:

[HTML]ImportError: No module named arcpy[/HTML]

Same message if I try and run the script in PyDev for Eclipse, or Idle. I've read this thread but with no joy.

Info
I'm on Windows 7, 64bit
this folder exits: C:\Python26\ArcGIS10.0
I don't know where Desktop10.pth file is?
I have no PYTHONPATH variable

Any pointers appreciated!
James
Tags (2)
0 Kudos
5 Replies
deleted-user-VeZur_n9o0OZ
New Contributor III
Update:

I have located Desktop10.pth here:C:\Python26\ArcGIS10.0\Lib\site-packages. It contains these entries:
C:\Program Files (x86)\ArcGIS\Desktop10.0\bin
C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy
C:\Program Files (x86)\ArcGIS\Desktop10.0\ArcToolbox\Scripts

Am i right in saying I need to reference arcpy somewhere centrally so python.exe can run my scripts outside of ArcGIS?

James
0 Kudos
AlessandroCinnirella
New Contributor III
how do you type your command?

if you don't add "python.exe" to your PATH system variable, you must specify it in the command line:


c:\Users\Yourname> c:\Python26\ArcGIS10.0\python.exe yourscript.py

ciao,
AC
0 Kudos
RuthEmerick
New Contributor II
See http://www.itechtalk.com/thread542.html for instructions on how to add the Python directory to your system's path variable.
0 Kudos
deleted-user-VeZur_n9o0OZ
New Contributor III
Thanks guys. I was running C:\Python26\python.exe in my bat file so have now changed this to C:\Python26\ArcGIS10.0\python.exe. Also, in PyDev preferences (Window > preferences > PyDev > Interpreter Python > I've updated interpreters to reflect this so I can now run my scripts in Eclipse. I ran the bat file successfully as a scheduled task all night.

Ruth, I have appended ';C:\Python26\ArcGIS10.0' to my Path environment variable. Is that correct? Should that resolve the following:

my script fails If I run it from windows explorer (double clicking it).
I receive the following message running my script in IDLE:    
import arcgisscripting
ImportError: DLL load failed: %1 is not a valid Win32 application.

Cheers,
James
0 Kudos
RuthEmerick
New Contributor II

my script fails If I run it from windows explorer (double clicking it).
I receive the following message running my script in IDLE:    
import arcgisscripting
ImportError: DLL load failed: %1 is not a valid Win32 application.


Check and make sure that the C:\Python26\ArcGIS10.0\Lib\site-packages\Desktop10.pth file contains the following two lines (you can edit it with Notepad):

C:\Program Files\ArcGIS\Desktop10.0\bin
C:\Program Files\ArcGIS\Desktop10.0\arcpy

If not, add them. Hopefully that's the problem.
0 Kudos