I have a very small test script (test.py) that I use to see if Python is installed and ready to use ArcPy. All it contains is:
print "Starting"
import os
print "OS imported"
import arcpy
print "ArcPy imported"
I’m running it under Vista SP1 with ArcGIS Desktop 10 SP1 and the only version of Python present is 2.6.5 which was installed by ArcGIS Desktop 10. ArcMap 10 SP1 is starting fine and the "import arcpy" and other arcpy functions work fine from the Python Window.
However, when I run “python test.py” from the DOS/cmd prompt, the first two print statements execute as expected, but the last one does not, so it seems to be failing/hanging on “import arcpy”. For a brief time on two separate days the script actually ran fine, but then it seems to stop working (which to me is bizarre). To try and figure what the problem is I have been reading Importing ArcPy and I think I have the system variables Path and PYTHONPATH set to appropriate values:
Path=C:\Program Files\weoapp;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;c:\Program Files\Common Files\Lenovo;C:\Program Files\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files\ThinkPad\ConnectUtilities\;C:\Program Files\Lenovo\Client Security Solution;C:\Windows\System32\WindowsPowerShell\v1. 0\;C:\Program Files\QuickTime\QTSystem;C:\Program Files\Windows Live\Shared;C:\Program Files\QuickTime\QTSystem\;C:\Python26\ArcGIS10.0
PYTHONPATH=C:\Python26\ArcGIS10.0
but I’ve also tried:
PYTHONPATH=C:\Python26
When I first noticed the problem I had both Python 2.5.x (C:\Python25) and 2.6.5 (C:\Python26) present, so I went to considerable trouble to remove both, and uninstall ArcGIS Desktop 10 SP1 before reinstalling ArcGIS Desktop 10 (which installed Python 2.6.5) and then its SP1 again.
Does anyone have an idea as to what may be causing “import arcpy” to hang for me most of the time, or have any ideas as to what debugging steps may be available to me?
Answer
arcpy (actually arcgisscripting which it wraps) extends a specific version of python. At arcgis 10.0 you need to run with python26. I'd make sure all the versions are matching.
Instead of doing this
C:\> test.py
Do this
C:\> C:\python26\Desktop10.0\python.exe test.py
Then you know it's starting the correct version of python. If that second line works, what's happening is that windows is starting python25, you'll need to do one of these
1) update windows file association for .py files (quick/technical)
2) uninstall python25 & 26 and install from the install disk (still pretty quick, less technical)
No comments:
Post a Comment