mahsa-ebrahimian
mahsa-ebrahimian

Reputation: 151

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.

Upvotes: 7

Views: 82453

Answers (8)

sfy
sfy

Reputation: 3238

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

Under

HKEY_CURRENT_USER\Software\Python\PythonCore\3.10\PythonPath

add

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

Under

HKEY_CURRENT_USER\Software\Python\PythonCore\3.10\InstallPath

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

Upvotes: 1

Rasla
Rasla

Reputation: 141

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!

Upvotes: 0

anonymous
anonymous

Reputation: 1

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.

Upvotes: 0

dwc035
dwc035

Reputation: 1

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

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

Upvotes: 0

Dalia Mokhtar
Dalia Mokhtar

Reputation: 39

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

Upvotes: 0

innov8
innov8

Reputation: 2219

'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.

Upvotes: 9

Vitalicus
Vitalicus

Reputation: 1379

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 %*"

Upvotes: 6

mahsa-ebrahimian
mahsa-ebrahimian

Reputation: 151

I found the solution:

setting global variable in cmd as below resolved the issue

C:> ftype Python="C:\Users\user x\AppData\Local\Programs\Python\Python36\python.exe %1 %*"

Upvotes: 5

Related Questions