1

I am attempting to execute a script mulitple times from the ArcMap python window (using different parameters that are hardcoded into the file).

The script runs the first time successfully, however it seems to "break" the python console, and other attempts at execfile are unsuccessful afterwards, until I restart arcgis.

Here's the a basic scenario:

  1. Start ArcGIS, open python console, type:

execfile(r"C:\Users\xxx\Desktop\test.py")

  1. Script executes successfully

  2. Modify test.py script

  3. Type execfile(r"C:\Users\xxx\Desktop\test.py")

  4. Python console returns to prompt

Any ideas on what might be happening? Workarounds?

9
  • What happens if test.py has only one line of code like print "Test worked!"? What do you "modify" in step 3?
    – PolyGeo
    Commented Feb 22, 2017 at 10:47
  • Tried the above, unfortunately doesn't work. Also tried a different script (e.g. test2.py), and it doesn't get loaded either. In step 3 I change some of the input in the variables Commented Feb 22, 2017 at 10:49
  • If I were to use my test.py and change it to print "Test2 worked!", would I see the same symptoms?
    – PolyGeo
    Commented Feb 22, 2017 at 11:01
  • 1
    Any particular reason you are using execfile instead of import and calling functions, or the more ArcGISy way of using a script tool?
    – user2856
    Commented Feb 22, 2017 at 11:22
  • 2
    I use execfile without issues all the time. There was one day where a restart was required and a script I have run 100s of times just "returned to the prompt" as you described. Have you closed and restarted ArcMap? Commented Feb 22, 2017 at 14:30

2 Answers 2

1

I was not able to reproduce this using my test.py script which started as:

print "Test worked!"

and in your step 3 was modified to:

print "Test2 worked!"

When I ran it from the Python window using ArcGIS Desktop 10.5 and your method I got:

>>> execfile(r"C:\Temp\test.py")
Test worked!
>>> execfile(r"C:\Temp\test.py")
Test2 worked!
>>>
2
  • Thanks for the test, I would like to specify that the above used to work for me too. However at one point I started facing the issues I describe in the post Commented Feb 22, 2017 at 11:26
  • I suspect the expedient, if restarting ArcMap does not resolve it, may be to uninstall/reinstall - it sounds like something has gone astray with your configuration.
    – PolyGeo
    Commented Feb 22, 2017 at 11:28
0

While restarting ArcMap did not resolve the issue, a full reboot brought it back to working state.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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