Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "Can't find a default Python" error

I am using python in a windows server(64 bit) and it is installed by another user in his own directory in C:\user\userx\AppData\Local\Programs\Python\Python36

All other users (excluding me) are able to run Python files on this server. I get the following error when I run a Python program:

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.

I tried running my code in the command line with set pylaunch_debug=1 and it showed below errors.

like image 986
mahsa-ebrahimian Avatar asked Jul 12 '26 03:07

mahsa-ebrahimian


2 Answers

'Can't find a default Python' is not from windows itself, but from the python launcher.

Resetting ftype (as in some other responses) directly to a specific python install should mask the error, but is bypassing the Python Launcher. The alternative is to fix actual problem. Perhaps more complex than simply making it go away, but masking it means a key feature, python launcher, has then been disabled.

If you have this error, check ftype by entering

 ftype Python.File

without setting a new value.

The normal value should be Python.File="C:\windows\py.exe" "%L" %*

Py.exe is the Python launcher. This launcher inspects python files and for the "shebang" line at the top of the file specifying which version of python will be used.

Py.exe is the program reporting 'cannot find a default python'. Resetting the ftype to directly load python will bypass the error, but will disables the intermediate step of py.exe which should select the correct python version for the file. If you a fine disabling py.exe, that is ok, but if you wish to fix py.exe, then try setting the environment variable PYLAUNCH_DEBUG like this (as the original poster had done):

set PYLAUNCH_DEBUG=1

Then trying again (or just enter py as a command) for more info on exactly what is failing.

For me the registry entry for

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\3.7\InstallPath

was missing and adding that key fixed the problem. You can edit the registry keys and set the one above for the relevant python version with required path, or add a py.ini file. Instruction for the py.ini are a little long for here, but i will add a link if anyone wants.

There are two problems with bypassing python launcher. Firstly the problem could return if a new version is added, and secondly the ability for programs to specify the correct python version is disabled.

like image 102
innov8 Avatar answered Jul 13 '26 16:07

innov8


Associate the correct file group with .py scripts:

assoc .py=Python.File

Redirect all Python files to the new executable:

ftype Python.File="C:\Path\to\pythonw.exe %1 %*"
like image 29
Vitalicus Avatar answered Jul 13 '26 15:07

Vitalicus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!