Windows insists associating .py files with the wrong version of Python
Changing the shebang (#! python3
) may help you, but you will have a problem: if your python script has parameters, they will be cut off when you run command
somepythonfile.py your_parameters
You will get py.exe running with just "somepythonfile.py" and NO parameters, believe me.
The method which worked for me is next: run the app http://www.nirsoft.net/utils/file_types_manager.html - this is a file association manager. Fix the association for python files to be
"C:\Windows\py.exe" "%1" %*
instead of
"C:\Windows\py.exe" "%1"
Or, alternatively, set
"C:\Python34\pythonw.exe" "%1" %*
explicitly - to match the desired version and omit the shebang line.
It seems that windows is not checking the whole path of the executable! Try to rename the python.exe of version 2 (respectively 3) to some temp name. Then associate with this name. And change everything back.
FYI you could check the file association with:
C:\Users\shadowed>assoc .py
.py=Python.File
C:\Users\shadowed>ftype Python.File
Python.File="C:\Python27\python.exe" "%1" %*
Try to add #!python3
to the very first line. Python 3.3 introduced Python Launcher for Windows that associates .py
with c:\windows\py.exe
. It launches the highest Python 2 by default.See https://stackoverflow.com/a/17245543/1346705