Saturday, September 20, 2014

Get python.exe to be Recognized by the Command Window

Tired of this error?
'python' is not recognized as an internal or external command, operable program or batch file.

It is often handy to run a python script from the windows command window, but it is a bit cumbersome to have to type in C:\python27\ArcGIS10.2\python.exe every time.  Here's how you get python as a recognized executable in the command window.

Path - System Environment Variable

Windows looks for executable files in a semicolon delimited list of directories stored in the Path system variable.

To add python to this list - click Start - and type "system variables" in the search input at the bottom.  There should be a result for "Edit the system environment variables".  You can also get there from the Control Panel - System - Advanced System Settings.

This brings up the System Properties dialog.  From this dialog click the "Environment Variables" button.  Under "System Variables", scroll down until you find the Path variable - click on it and click Edit...  In the "Variable value:" box, find the end of the text and add a semicolon (;), then add the path to your python.exe file (usually in C:\Python[version number]\ArcGIS[version number]\ - at the time of this writing it would be C:\Python27\ArcGIS10.2\).  Now click OK on each of the open dialogs.  Python will now execute from the command window no matter where you are in your directory structure.


If you have a command window open at the time you change the variable, that command window still won't recognize the python command.  You need to close the command window and open another one.

Each time you upgrade your version of ArcGIS for Desktop, the location of the python executable may change - it may become something like - C:\Python32\ArcGIS10.3, so you need to modify your path variable again.

No comments:

Post a Comment