win - python 2.7 & 3.6 - switching version that script uses from shell

0

I have placed a script test.py in my %USERPROFILE% folder:

import sys
print("TEST", sys.version_info, sys.executable)

When running cmd (WIN+R) and then typing test+ENTER the following is returned:

C:\Users\wittrup>test
('TEST', sys.version_info(major=2, minor=7, micro=10, releaselevel='final', serial=0), 'C:\\Python27\\python.exe')

I would like this to run with python 3.6.

There are two python versions installed:

  • C:\Python27\python.exe
  • C:\Users\wittrup\AppData\Local\Continuum\Anaconda3

echo %path:;=&echo.% shows:

C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\pythonxy\SciTE-3.5.1-4
C:\Program Files (x86)\pythonxy\console
C:\Users\wittrup\AppData\Local\Microsoft\WindowsApps
C:\Users\wittrup\AppData\Local\Continuum\Anaconda3
C:\Users\wittrup\AppData\Local\Continuum\Anaconda3\Scripts

(and a bunch of other stuff I deemed irrelevant for this case)

C:\Users\wittrup>echo %PATHEXT%
.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW

Registry:

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe
C:\Users\wittrup\AppData\Local\Continuum\Anaconda3\python.exe

Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\python.exe
C:\Users\wittrup\AppData\Local\Continuum\Anaconda3\python.exe

What beats me here, is I really cannot figure out how Windows ends up running the script with python 2.6 - any other places to look?

C:\Users\wittrup>ver
Microsoft Windows [Version 10.0.17134.407]

wittrup

Posted 2018-12-08T12:06:49.913

Reputation: 101

1Add to the post the output of assoc .py and ftype | findstr py. – harrymc – 2018-12-08T13:06:36.293

Answers

0

Able to solve by question-comment (thanks!).

; Note the detail about administrator privileges
C:\WINDOWS\system32>ASSOC .py
.py=Python.File

C:\WINDOWS\system32>FTYPE | FINDSTR Python.File
Python.File="C:\Python27\python.exe" "%1" %*

C:\WINDOWS\system32>FTYPE /?
Displays or modifies file types used in file extension associations

FTYPE [fileType[=[openCommandString]]]

  fileType  Specifies the file type to examine or change
  openCommandString Specifies the open command to use when launching files
                    of this type.
; more ...

C:\WINDOWS\system32>FTYPE Python.File="python.exe" "%1" %*
Python.File="python.exe" "%1" %*

And I'll let environment variables handle the rest.

wittrup

Posted 2018-12-08T12:06:49.913

Reputation: 101