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:

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?

I found this to be a very useful answer so have upvoted it. When I do "C:\python26\ArcGIS10.0\python.exe test.py" on one laptop it still hangs (this one only has Python 2.6 on it). On the other (which has both Python 2.5 and 2.6 installed) that works but perplexingly "python test.py" has started to work again on that second laptop too.
–
PolyGeo♦Jan 18 '11 at 10:28

I still have this issue but this was the answer I learned the most from.
–
PolyGeo♦Jul 20 '11 at 23:33

This is more of a general troubleshooting help, than a python + arcgis answer. If it hangs it's executing the python module, does it ever timeout with an error?

So hopefully it's one of:

waiting for network connection

network port (check firewall settings)

DNS

If it's waiting for something to load (e.g. something in ArcGIS). But it should be possible to find out what by either running a python debugger on it or run System Monitor to see which files python loads/reads.

Thanks for trying to help with this Erik. However, I don't think it is a network port, firewall or DNS issue because on the two Vista SP2 laptops that I've tested it sometimes works on both but not always - and I'm confident that I am not altering network port, firewall or DNS on either.
–
PolyGeo♦Jan 18 '11 at 10:17