Sublime Forum

Error running Python code

#1

I just installed Sublime Text and I just tried to run a hello world program but received this error message.

[WinError 2] The system cannot find the file specified
[cmd: [‘py’, ‘-u’, ‘C:\Users\noaho\OneDrive\Desktop\helloworld.py’]]
[dir: C:\Users\noaho\OneDrive\Desktop]
[path: C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\noaho\AppData\Local\Microsoft\WindowsApps;]
[Finished]

I have the file saved as “helloworld.py” on my desktop. Python 3.9.5 is installed as well. Does anyone else have this problem? Thanks

0 Likes

#2

In ST4, the default build system for Python changed so that instead of invoking python it invokes python3 (on Linux/MacOS) and py (on Windows).

The idea here is that there’s a checkbox that you have to check when you install Python on windows to get the installer to update the PATH so that the command prompt (and thus Sublime) can see and run the Python interpreter, but this is not checked by default.

On Windows, the Python setup program will also install a program named py into the Windows folder, which is a helper that will find and execute the correct version of Python automagically. There’s a checkbox for this as well, but it defaults to being checked.

Your error diagnostic indicates that you’re running the newer build (py is being executed) but it can’t be found and also the PATH as displayed in the output doesn’t include the Python install location either. From that I would guess that when you installed Python, the py helper box was not checked.

As a test, you could try running py from a command prompt outside of Sublime to see if that works, but failing that the way forward would be to manually update the PATH to include the install location of Python and then make a custom sublime-build file that executes python instead of py, or reinstalling Python and ensuring that the checkbox for the py helper is checked.

This video also talks about this, and includes at the end a quick tutorial on how you can create a custom build based off of the existing one. Here you would use something like this to change the windows command to python from py after you update the PATH.

1 Like