Search code examples
pythonpython-3.xsubprocessarcpy

How to run python script #!python3 command with specific sub version of python 3


I have two versions of Python 3.6.1 and 3.6.2

I have a sample script below:

#! python3
import arcpy
print ("Gurminder")

The code runs by default with 3.6.1 as I have specified it to run with python3

However is there any way that I can force the compiler to run the with python 3.6.2?

Is there any parameter where I can specify the subversion of the python interpreter to be used?

I am aware of running the python with its interpreter executables for example:

"C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\python.exe" D:\inetpud_backup_17_04_2018\Gurminder\Cases\02104091\test.py'

The command works fine in command prompt however when it is run using os or subprocess module I get the error for the white space between the Program Files

Hence on researching the issue, I found the workaround on specifying the version in the header. Is there any way to define the subversion as well?


Solution

  • You could use a direct path to Python 3.6.2 as your shebang line:

    #!C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3/python.exe"
    

    I also see no reason why this is necessary. Python 3.6.1 and Python 3.6.2 are exactly the same except for the fixes.

    There are no packages you cannot use in Python 3.6.1 and 3.6.2. Why not just use 3.6.2 instead?