Share via

Multiple Python versions installed : how to set the default version for py.exe (Python Launcher for Windows) for CMD and for “Open with”

Anonymous
2021-06-26T12:30:06+00:00

In brief:
I have two versions of Python installed: Python 3.6 and Python 3.9. I want to open all my .py and  .pyw (ex: when I double click on them) with Python Launcher for Windows. I want the default version of the Python launcher for Windows to be Python 3.6 so that the files without a shebang are open with Python 3.6. Python 3.9 should only be used for files with a shebang #! python3.9

When I right click on a file, choose open with and select C:\Windows\py.exe, then by default (without any shebang), it's Python 3.9 that is open. When I type py in a CMD I get Python 3.6.5.
But if I double click on C:\Windows\py.exe the console is Python 3.9.5.

How can I make sure that if I set open all .py' to C:\Windows\py.exe, then if they don't have a sheband they will be started with Python 3.6.5`?

In details :

I was running air purifier on Python 3.6 only until I installed Python 3.9 along side. I haven't yet updated all the package to Python 3.9 so I want the default Python to be 3.6. For my scripts that need to use Python 3.9, I use the shebang #! python3.9.

So I would like to set the Opens with... default to C:\Windows\py.exe but if I do that my scripts are open in Python 3.9.5 and so they failed.

What I have already done:

  1. I have created a C:\Windows\py.ini with the default set to python=3.6 (same for pyw).
  2. In path, I have move C:\Users\user\AppData\Local\Programs\Python\Python36\ above C:\Users\user\AppData\Local\Programs\Python\Python39.
  3. I have set another environment variable PY_PYTHON to PY_PYTHON=3.6.
  4. I have run assoc .py=Python
  5. The Windows documentation says that The py.exe launcher will automatically select the most recent version of Python you've installed, so I reinstalled Python 3.6 (after having already installed Python 3.9) but, still the default is set to Python 3.9 when I open a file with C:\WINDOWS\py.exe
  6. ftype | find "Python" return this Python.ArchiveFile="C:\WINDOWS\py.exe" "%L" %*
    Python.CompiledFile="C:\WINDOWS\py.exe" "%L" %*
    Python.File="C:\WINDOWS\py.exe" "%L" %*
    Python.NoConArchiveFile="C:\WINDOWS\pyw.exe" "%L" %*
    Python.NoConFile="C:\WINDOWS\pyw.exe" "%L" %*
Windows for home | Windows 10 | Accessibility

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-07-01T17:32:30+00:00

    Hi,

    Thank you for writing to Microsoft Community Forums.

    I understand that you want to set Python launcher for CMD and Open with.

    However, we do have a dedicated forum where you should find support. I would suggest you to post your query on Windows on Q&A, where we have support professionals with expertise to assist you with your query.

    Regards,

    Nikhar Khare

    Microsoft Community - Moderator

    Was this answer helpful?

    0 comments No comments