我在 Windows 服务器(64 位)中使用 python,它由另一个用户安装在他自己的目录中C:\user\userx\AppData\Local\Programs\Python\Python36
所有其他用户(不包括我)都可以在此服务器上运行 Python 文件。当我运行 Python 程序时,出现以下错误:
C:\Users\user x\AppData\Local\Programs\Python\Python36>test.py
launcher build: 32bit
launcher executable: Console
File 'C:\Users\my user\AppData\Local\py.ini' non-existent
File 'C:\Windows\py.ini' non-existent
Called with command line: "C:\Users\user x\AppData\Local\Programs\Python\Python
36\test.py"
maybe_handle_shebang: read 12 bytes
maybe_handle_shebang: BOM not found, using UTF-8
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: unable to open PythonCore key in HKLM
found no configured value for 'python'
search for default Python found no interpreter
Can't find a default Python.
我尝试在命令行中运行我的代码set pylaunch_debug=1
它显示以下错误。
“找不到默认的 Python”不是来自 Windows 本身,而是来自 python 启动器。
重置ftype
(如在其他一些响应中)直接到特定的 python 安装应该会掩盖错误,但会绕过 Python 启动器。另一种选择是解决实际问题。也许比简单地让它消失更复杂,但屏蔽它意味着一个关键功能,Python 启动器,随后被禁用。
如果出现此错误,请输入检查 ftype
ftype Python.File
无需设置新值。
正常值应该是Python.File="C:\windows\py.exe" "%L" %*
Py.exe
is the Python启动器 https://docs.python.org/3/using/windows.html#launcher。该启动器检查 python 文件并查找“shebang https://stackoverflow.com/questions/6908143/should-i-put-shebang-in-python-scripts-and-what-form-should-it-take文件顶部的“行指定将使用哪个版本的 python。
Py.exe 是报告“找不到默认 python”的程序。重置ftype
直接加载 python 将绕过错误,但会禁用 py.exe 的中间步骤,该步骤应该为文件选择正确的 python 版本。如果您可以很好地禁用 py.exe,那没问题,但如果您想修复 py.exe,请尝试设置环境变量PYLAUNCH_DEBUG
像这样(正如原始海报所做的那样):
set PYLAUNCH_DEBUG=1
然后重试(或者只是输入py
作为命令)以获取有关失败原因的更多信息。
对我来说,注册表项为
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\3.7\InstallPath
丢失了,添加该键解决了问题。您可以编辑注册表项并为相关 python 版本设置所需路径,或者添加 py.ini 文件。 py.ini 的说明在这里有点长,但如果有人需要,我会添加一个链接。
绕过 python 启动器有两个问题。首先,如果添加新版本,问题可能会再次出现;其次,程序指定正确 python 版本的功能被禁用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)