Select to view content in your preferred language

Time to Run Scripts in Various IDEs / Editors

10-27-2019 12:08 PM
Occasional Contributor III

Wanted to ask if anyone else has experienced this, or could provide any insight or ideas. I'd used PythonWin for scripting with arcpy in the past, and it seemed quick and light, no real issues. On and off over the last year or so I've experimented with other more modern IDEs / editors with more bells and whistles, but I've noticed that my scripts take longer to run in every other program...

In PythonWin, usually the first run of a .py file takes a few extra seconds, I'm guessing when importing arcpy - but subsequent runs are usually very quick. In the other programs I've tried to-date, each run takes nearly as long as the first, usually adding anywhere from ~10 to 20sec when compared to PythonWin. For example, in PythonWin, a first run might take ~12sec to run, but subsequent runs are under a second. In the others, time elapsed would always be close to the first run time taken. I've observed this behavior in Visual Studio Code, Sublime Text, PyCharm (and I believe Spyder a while back too). I really like at least some features available in each of the programs listed, and the extra time is not a deal-breaker, just bothersome.

Would this have something to do with how the programs themselves run, or is something else more likely, such as configuration, or install locations, etc.? I do see that PythonWin is installed in C:\Python27\ArcGIS10.6\Lib\site-packages, so maybe that is part of the answer...

PythonWin running 2.7, other programs 2.7 or 3.6 (same running time issue observed in 3.6)



0 Kudos
3 Replies
MVP Emeritus

Does your script import packages/modules?

Spyder, for instance, has an option to force the reloading of user modules at runtime.   This can be disabled if you want and you can force reload of modules in python 3.

Some IDE's, like pythonwin don't, forcing you to use  "reload"  from importlib.  (pythonwin running python 3.6.8 from the ArcGIS Pro distribution).

from importlib import reload

import sys

<module 'sys' (built-in)>‍‍‍‍‍‍‍‍

Also some can't be 'reloaded' like arcpy, but you can access arcpy functionality by circumventing that constraint and just importing the modules you want from it like gp or env or arcgisscripting.

Just examine the script in C:\Your_Install_Path\Resources\ArcPy\arcpy for your ArcGIS Pro installation to get an idea what "import arcpy" actually does and why it fails on reload.

In any event, in order to compare the run times between IDE's you have to make sure they are being compared on equal footing,  and I am pretty sure you won't find a difference beyond what it takes to get beyond the imports and get python running.

If this related to importing arcpy, you should really invest some time to examine what happens, so you can skip importing unneed clutter in your namespace and perhaps cut down on import times and permit reloads if desired.

One short missive on the topic


Occasional Contributor III

Thank you Dan, very much appreciated!

Will report back after further review, any testing.

0 Kudos
Occasional Contributor III

Very delayed response here, but here's an update:

Didn't end up finding an option to disable forced reload of modules for the versions of software I had installed - so I followed Dan Patterson's tips for cloning in Pro and installing Spyder (can all be accessed from here). Even without changing that setting, the speed was immediately much faster than what I had been seeing - so importing arcpy was not the culprit after all...

Went back to a couple of the other programs to review again and found:

  In PyCharm (2018.3.7), sys is imported each run before the .py file is run, which takes a few extra seconds before the script actually runs. There may be some way around this, not sure. Once the script runs however, re-entering runfile('yourscript', wdir='yourprojectdir') within the same tab executes immediately, even after modifying.

  In Visual Studio Code (1.41.0), choosing Run Code would always run with 2.7 as the interpreter, even though the path to Python was set as 3.6.8 (and displayed as such in bottom left of screen). Choosing to Run Python File In Terminal instead would run with 3.6.8, and much faster. Potentially another settings issue somewhere.

  Learned that setting up Sublime Text (3.2.2) to work with more than one interpreter is not nearly as easy as any of the others, so I've held off for now.

The conclusion is that I have at least three modern options now that feel as quick, or nearly as quick as what I had experienced with PythonWin in the past, which is what I was after. And as it stands today, Spyder is the front-runner in my case since it will not require any further investigation to run my scripts in a manner I'm familiar with.