I have set the environment variables so that python 3.6 is the version that is run when I use the python command in the terminal, but when I run a python script from the terminal it uses python 2.7.
I have included a folder called MyScripts in the path so that i can run these scripts directly from the terminal without specifying the path.
Running just python shows Python 3.6.4

But executing the script shows 2.7.14. This is the script v27.py
import sys
print(sys.version)
print(sys.executable)
And this is the output

As you are running the Python Script (as a executable) without specifying python in command prompt, it will not use the python path set in Environment Variables. Instead, windows will run the Default Program associated for that extension. You can find the associated program under Control Panel\All Control Panel Items\Default Programs\Set Associations
Either you can go to ControlPanel to change the Default Program or your can run below command in cmd (need elevated permission to do this)
C:\> assoc .py=Python
C:\> ftype Python="C:\Users\asleb\AppData\Local\Programs\Python\Python36-32\python.exe" "%1" %*
Also, if you want to run without extension (like v27 instead of v27.py) then, you need to add .py to the PATHEXT environment variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With