如何修复 "Can't find a default Python" 错误
How to fix "Can't find a default Python" error
我在 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
设置我的代码,但它显示了以下错误。
我找到了解决方案:
如下在 cmd 中设置全局变量解决了问题
C:> ftype Python="C:\Users\user x\AppData\Local\Programs\Python\Python36\python.exe %1 %*"
将正确的文件组与 .py 脚本相关联:
assoc .py=Python.File
将所有 Python 文件重定向到新的可执行文件:
ftype Python.File="C:\Path\to\pythonw.exe %1 %*"
“找不到默认 Python”不是来自 windows 本身,而是来自 python 启动器。
直接将 ftype
重置为特定 python 安装应该会掩盖错误,但会绕过 Python 启动器。另一种方法是解决实际问题。也许比简单地让它消失更复杂,但屏蔽它意味着一个关键功能,python 启动器,然后被禁用。
如果出现此错误,请输入
检查 ftype
ftype Python.File
没有设置新值。
正常值应该是Python.File="C:\windows\py.exe" "%L" %*
Py.exe
是文件顶部的 Python launcher. This launcher inspects python files and for the "shebang" 行,指定将使用哪个版本的 python。
Py.exe为节目报道'cannot find a default python'。将 ftype
重置为直接加载 python 将绕过错误,但会禁用 py.exe 的中间步骤,这应该 select 文件的正确 python 版本.如果你很好地禁用 py.exe,那没问题,但如果你想修复 py.exe,那么尝试像这样设置环境变量 PYLAUNCH_DEBUG
(正如原始海报所做的那样):
set PYLAUNCH_DEBUG=1
然后重试(或仅输入 py
作为命令)以获取有关失败原因的详细信息。
对我来说
的注册表项
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore.7\InstallPath
丢失并添加该密钥解决了问题。您可以编辑注册表项并为具有所需路径的相关 python 版本设置上面的注册表项,或者添加一个 py.ini 文件。 py.ini 的说明在这里有点长,但如果有人需要,我会添加一个 link。
绕过 python 启动器有两个问题。首先,如果添加了新版本,问题可能 return,其次,程序指定正确 python 版本的能力被禁用。
通过在系统变量中编辑 PATH 对我有用:
adding python path: "..................\Python36"
并在 运行 代码的同时在 cmd 上写入,代码文件路径前的单词“python”如:
python code_file_name.py
阅读#innov8 后,在注册表中进行了一些额外的探索,发现除了完整的 HKCU\Software\Python 键外,还有一个“空”HKLM\Software\Python 键,它没有子键或值。
删除有问题的 HKLM 密钥解决了我的启动器问题。
设置文件默认使用Python打开,如果不行就设置为其他python版本。
另一种解决方案是在您的 cmd 中写入 python yourfilename.py
。
我在 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
设置我的代码,但它显示了以下错误。
我找到了解决方案:
如下在 cmd 中设置全局变量解决了问题
C:> ftype Python="C:\Users\user x\AppData\Local\Programs\Python\Python36\python.exe %1 %*"
将正确的文件组与 .py 脚本相关联:
assoc .py=Python.File
将所有 Python 文件重定向到新的可执行文件:
ftype Python.File="C:\Path\to\pythonw.exe %1 %*"
“找不到默认 Python”不是来自 windows 本身,而是来自 python 启动器。
直接将 ftype
重置为特定 python 安装应该会掩盖错误,但会绕过 Python 启动器。另一种方法是解决实际问题。也许比简单地让它消失更复杂,但屏蔽它意味着一个关键功能,python 启动器,然后被禁用。
如果出现此错误,请输入
检查 ftype ftype Python.File
没有设置新值。
正常值应该是Python.File="C:\windows\py.exe" "%L" %*
Py.exe
是文件顶部的 Python launcher. This launcher inspects python files and for the "shebang" 行,指定将使用哪个版本的 python。
Py.exe为节目报道'cannot find a default python'。将 ftype
重置为直接加载 python 将绕过错误,但会禁用 py.exe 的中间步骤,这应该 select 文件的正确 python 版本.如果你很好地禁用 py.exe,那没问题,但如果你想修复 py.exe,那么尝试像这样设置环境变量 PYLAUNCH_DEBUG
(正如原始海报所做的那样):
set PYLAUNCH_DEBUG=1
然后重试(或仅输入 py
作为命令)以获取有关失败原因的详细信息。
对我来说
的注册表项Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore.7\InstallPath
丢失并添加该密钥解决了问题。您可以编辑注册表项并为具有所需路径的相关 python 版本设置上面的注册表项,或者添加一个 py.ini 文件。 py.ini 的说明在这里有点长,但如果有人需要,我会添加一个 link。
绕过 python 启动器有两个问题。首先,如果添加了新版本,问题可能 return,其次,程序指定正确 python 版本的能力被禁用。
通过在系统变量中编辑 PATH 对我有用:
adding python path: "..................\Python36"
并在 运行 代码的同时在 cmd 上写入,代码文件路径前的单词“python”如:
python code_file_name.py
阅读#innov8 后,在注册表中进行了一些额外的探索,发现除了完整的 HKCU\Software\Python 键外,还有一个“空”HKLM\Software\Python 键,它没有子键或值。
删除有问题的 HKLM 密钥解决了我的启动器问题。
设置文件默认使用Python打开,如果不行就设置为其他python版本。
另一种解决方案是在您的 cmd 中写入 python yourfilename.py
。