The documentation for Python 3.5 describes this behavior:
The shebang /usr/bin/env line shape has another special property. Before looking for installed Python interpreters, this form will look for the PATH executable for the Python executable. This is consistent with the behavior of the Unix env program, which performs a PATH search.
Oddly enough, the same functionality applies to Python 3.4 (or at least version 3.4.3), despite the corresponding documentation page for Python 3.4 without mentioning it. I have included playback of this behavior at the bottom of this answer.
It seems your script contains the shebang line #!/usr/bin/env python at the top and C:\Python34 is on your PATH system until C:\Python27 . You will say in the comment that
It is important that this particular script does not have a shebang
but the line
parse_shebang: found command: python
in your startup output, the fact that the script really needs to have a shebang string gives out.
I have Python 2.7.10 and Python 3.4.3 installed on my system, from 3.4 to 2.7 on PATH . I also have a py.ini file in C:\Users\Luke\AppData\Local , which contains the following:
[defaults] python=2
and a test.py script containing
#!/usr/bin/env python import sys; print(sys.version_info)
I set the environment variable PYLAUNCH_DEBUG to 1 . By running this script with py test.py , I get the following output:
launcher build: 32bit launcher executable: Console Using local configuration file 'C:\Users\Luke\AppData\Local\py.ini' File 'C:\WINDOWS\py.ini' non-existent Called with command line: test.py maybe_handle_shebang: read 60 bytes maybe_handle_shebang: BOM not found, using UTF-8 parse_shebang: found command: python searching PATH for python executable Python on path: C:\Python34\python.EXE located python on PATH: C:\Python34\python.EXE run_child: about to run 'C:\Python34\python.EXE test.py' sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0) child process exit code: 0
If I change my test.py script to
#! python import sys; print(sys.version_info)
(i.e. remove /usr/bin/env from the shebang line) and run py test.py , I get the following:
launcher build: 32bit launcher executable: Console Using local configuration file 'C:\Users\Luke\AppData\Local\py.ini' File 'C:\WINDOWS\py.ini' non-existent Called with command line: test.py maybe_handle_shebang: read 48 bytes maybe_handle_shebang: BOM not found, using UTF-8 parse_shebang: found command: python locating Pythons in 64bit registry locate_pythons_for_key: unable to open PythonCore key in HKCU locate_pythons_for_key: unable to open PythonCore key in HKLM locating Pythons in native registry locate_pythons_for_key: unable to open PythonCore key in HKCU locate_pythons_for_key: C:\Python27\python.exe is a 32bit executable locate_pythons_for_key: C:\Python27\PCBuild\python.exe: The system cannot find the path specified. locate_pythons_for_key: C:\Python27\PCBuild\amd64\python.exe: The system cannot find the path specified. locate_pythons_for_key: C:\Python34\python.exe is a 32bit executable locate_pythons_for_key: C:\Python34\PCBuild\python.exe: The system cannot find the path specified. locate_pythons_for_key: C:\Python34\PCBuild\amd64\python.exe: The system cannot find the path specified. found configured value 'python=2' in C:\Users\Luke\AppData\Local\py.ini search for default Python found version 2.7 at 'C:\Python27\python.exe' run_child: about to run 'C:\Python27\python.exe test.py' sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0) child process exit code: 0