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

Question:

I am using python in a windows server(64 bit) and it is installed by another user in his own directory in C:useruserxAppDataLocalProgramsPythonPython36

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:Usersuser xAppDataLocalProgramsPythonPython36>test.py
launcher build: 32bit
launcher executable: Console
File 'C:Usersmy userAppDataLocalpy.ini' non-existent
File 'C:Windowspy.ini' non-existent
Called with command line: "C:Usersuser xAppDataLocalProgramsPythonPython
36test.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.

Asked By: mahsa-ebrahimian

||

Answers:

I found the solution:

setting global variable in cmd as below resolved the issue

C:> ftype Python=”C:Usersuser xAppDataLocalProgramsPythonPython36python.exe %1 %*”

Answered By: mahsa-ebrahimian

Associate the correct file group with .py scripts:

assoc .py=Python.File

Redirect all Python files to the new executable:

ftype Python.File="C:Pathtopythonw.exe %1 %*"
Answered By: Vitalicus

‘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:windowspy.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

ComputerHKEY_LOCAL_MACHINESOFTWAREPythonPythonCore3.7InstallPath

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.

Answered By: innov8

it works for me by edit PATH in system variables:

adding python path: "………………Python36"

and write on cmd while running the code, word "python" before code’s file path like:

python code_file_name.py
Answered By: Dalia Mokhtar

After reading #innov8, some additional poking about in the registry showed that in addition to the complete HKCUSoftwarePython key, there was an "empty" HKLMSoftwarePython key which had no sub-keys or values.

Removing the faulty HKLM key resolved my problem with the launcher.

Answered By: dwc035

Set the file to be opened with Python as default, and if it doesn’t work then set it to the other python version.

An alternative solution would be writing python yourfilename.py in your cmd.

Answered By: anonymous

Actually the problem ocurs when python is not in the Environmental Variables.

Unintall and reinstall python! then Check Add Python to Path Check box on Instalation.

Close and Reopen Sublime! Now its Fixed!

Answered By: Rasla

I was using python installed via scoop which won’t add registry entries. so python launcher won’t work as expected.

Under

HKEY_CURRENT_USERSoftwarePythonPythonCore3.10PythonPath

add

"YOUR_PYTHON_PATH\Python310\Lib\;YOUR_PYTHON_PATH\Python310\DLLs\;

Under

HKEY_CURRENT_USERSoftwarePythonPythonCore3.10InstallPath

add

YOUR_PYTHON_PATH\Python310\

Create a key ExecutablePath whose value is YOUR_PYTHON_PATH\python.exe

Create a key WindowedExecutablePath, set its value: YOUR_PYTHON_PATH\pythonw.exe

Here is an image to show what it looks like
enter image description here

Answered By: sfy
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.