“如何修复”;Can';“找不到默认的Python”;错误

“如何修复”;Can';“找不到默认的Python”;错误,python,python-3.x,python-3.6,Python,Python 3.x,Python 3.6,我在windows服务器(64位)中使用python,它由另一个用户安装在他自己的目录中C:\user\userx\AppData\Local\Programs\python\python 36 所有其他用户(不包括我)都可以在此服务器上运行Python文件。我在运行Python程序时遇到以下错误: C:\Users\user x\AppData\Local\Programs\Python\Python36>test.py launcher build: 32bit launcher ex

我在windows服务器(64位)中使用python,它由另一个用户安装在他自己的目录中
C:\user\userx\AppData\Local\Programs\python\python 36

所有其他用户(不包括我)都可以在此服务器上运行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启动器

直接重置特定python安装的
ftype
(与其他一些响应一样)应该会掩盖错误,但会绕过python启动程序。另一种方法是解决实际问题。也许比简单地让它消失更复杂,但屏蔽它意味着一个关键特性,python launcher,随后被禁用

如果出现此错误,请通过输入来检查ftype

 ftype Python.File
不设置新值

正常值应为
Python.File=“C:\windows\py.exe”“%L”%*

Py.exe
是最新版本。此启动器检查python文件,并在文件顶部的“”行中指定将使用哪个版本的python

Py.exe是报告“找不到默认python”的程序。重置
ftype
以直接加载python将绕过该错误,但将禁用py.exe的中间步骤,该步骤应为文件选择正确的python版本。如果禁用py.exe没有问题,但如果希望修复py.exe,请尝试如下设置环境变量
PYLAUNCH\u DEBUG
(如原始海报所示):

然后再试一次(或只需输入
py
作为命令),以获取有关失败原因的详细信息

对我来说

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\3.7\InstallPath
丢失并添加该键修复了问题。您可以编辑注册表项,并使用所需路径为相关python版本设置上面的注册表项,或者添加py.ini文件。关于py.ini的说明在这里有点长,但是如果有人需要,我会添加一个链接


绕过python启动器有两个问题。首先,如果添加新版本,问题可能会返回,其次,程序指定正确python版本的功能被禁用。

通过在系统变量中编辑路径,它对我有效:

正在添加python路径:“………\Python36”

并在运行代码时在cmd上写入,在代码的文件路径前加上单词“python”,如:

python code_file_name.py
在阅读了#innov8之后,在注册表中进行了一些额外的探索,发现除了完整的HKCU\Software\Python键之外,还有一个“空”HKLM\Software\Python键,它没有子键或值


删除错误的HKLM密钥解决了我的启动程序问题。

您需要设置路径变量编辑系统环境变量并向itI追加“C:\user\userx\AppData\Local\Programs\Python\Python36”。我也已经设置了路径变量。请尝试在cmdin cmd Python test.py works中运行Python解释器,但test.py没有。但我想解决这个问题,以便能够使用IDE。文件类型“Python”找不到或没有与之相关的打开命令。只是对这个问题的一个小更正:我发现我只需要在路径上加引号,而不是在参数上加引号!因此,在Windows中,类似于ftype Python.File=“C:\Path\to\pythonw.exe”%1%*的内容,您可能需要以管理员身份运行命令提示符来设置关联。
python code_file_name.py