[GIS] Change which default python install runs .py scripts a the command prompt

installationpython

I have 3 installations of python on my machine currently, the ArcGIS install, the QGIS install, and an Anaconda install. The Anaconda is the on that I use predominantly. If I run a .py script (checkSource.py) with the following lines at the command prompt I get different results depending how I call it :

import sys
sys.prefix

C:\Users\RDebbout> checkSource.py
'C:\Python27\ArcGISx6410.3'

C:\Users\RDebbout> python checkSource.py
'C:\Users\RDebbout\AppData\Local\Continuum\Anaconda'

Will running .py scripts at the command line always search for the C:\Python27 install first? Is there a way to change this? I never do anything with the ArcGIS install other than import arcpy into the Anaconda install through the .pth file and would like to keep it sidelined from being used at the command prompt, so if I run a .py file there I want it to default to the Anaconda install, not the Arc install

Best Answer

You can do this with a batch file by explicitly pointing to your ArcGIS install:

start C:\Python27\ArcGIS10.3\python.exe C:\Path\to_the\script\to_run.py

You can apply the same logic to the cmd and point it to your desired python interpreter...If you are using a more robust Python IDE, you may even be able to point that to which version to use when running your script.

Related Question