【发布时间】:2023-03-14 16:27:01
【问题描述】:
简而言之:
我安装了两个版本的 Python:Python 3.6 和 Python 3.9。
我想用 Windows 的 Python Launcher 打开我所有的 .py 和 .pyw(例如:当我双击它们时)。我希望 Windows 的 Python 启动器的默认版本是 Python 3.6,以便使用 Python 3.6 打开没有 shebang 的文件。 Python 3.9 只能用于带有 shebang #! python3.9
当我右键单击一个文件时,选择open with 并选择C:\Windows\py.exe,然后默认情况下(没有任何shebang),它是打开的Python 3.9。
当我在CMD 中输入py 时,我得到Python 3.6.5。
但是如果我双击C:\Windows\py.exe,控制台是Python 3.9.5。
如果我设置了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`,我该如何确定?
详情:
我只在 Python 3.6 上运行,直到我同时安装了 Python 3.9。我还没有将所有包更新到 Python 3.9,所以我希望默认 Python 为 3.6。对于需要使用 Python 3.9 的脚本,我使用 shebang #! python3.9。
所以我想将Opens with... 默认设置为C:\Windows\py.exe,但如果我这样做,我的脚本会在Python 3.9.5 中打开,因此它们失败了。
我已经做了什么:
-
我创建了一个
C:\Windows\py.ini,默认设置为python=3.6(pyw也是如此)。 -
在路径中,我已将
C:\Users\user\AppData\Local\Programs\Python\Python36\移动到C:\Users\user\AppData\Local\Programs\Python\Python39上方。 -
我已将另一个环境变量
PY_PYTHON设置为PY_PYTHON=3.6。 -
我已经跑
assoc .py=Python -
Windows documentation 表示
The py.exe launcher will automatically select the most recent version of Python you've installed,所以我重新安装了 Python 3.6(在已经安装了 Python 3.9 之后),但是当我使用C:\WINDOWS\py.exe打开文件时,默认设置仍然设置为 Python 3.9 -
ftype | find "Python"返回这个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 10
【问题讨论】:
-
您目前如何启动 python?从 Windows 文件夹启动它的原因是什么?
-
which py的结果是什么? -
@TheLazyScripter
py.exe应该在 Windows 文件夹中。请参阅文档。 -
更新路径后,您是打开了一个全新的 cmd 窗口,还是使用了在更改路径之前打开的那个? cmd 窗口不会根据系统控件所做的更改动态更新其环境。
-
是的
py.exe应该位于 Windows 文件夹中(为所有用户安装时)。但是,直接 exe 位于appdata\local\programs\Python\MyPythonVersion内部。并且路径变量应该链接到这里而不是 Windows 文件夹。
标签: python python-3.x cmd window launcher