Sublime Forum

Sublime text and wrong path for python? Help

#1

I have the latest python and sublime text installed. I try to run a basic hello world test and get:

[WinError 2] The system cannot find the file specified

[cmd: ['python3', '-u', '']]

[dir: C:\Program Files (x86)\python_working_1]

[path: C:\Python3.9.1;C:\Program Files (x86)\VMware\VMware Workstation\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Users\Local User\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\Local User\AppData\Local\Programs\Python\Python310;C:\Python3.9.1\Scripts;C:\Python3.9.1;C:\Users\Local User\AppData\Local\Microsoft\WindowsApps] [Finished]

That is when I use python3 on sublime text and when I use just python to build then I receive:

C:\Users\Local User\AppData\Local\Programs\Python\Python310\python.exe: can't find 'main' module in '' [Finished in 157ms]
0 Likes

#2

This diagnostic shows you what command this build system is trying to execute; here is is the program python3 with the first argument being -u and the second argument being an empty string.

The python interpreter expects you to provide it the name of the file that you’re running, but here no filename is being provided.

This error message from a different build system is just the error that Python is displaying; the full error being:

can't find 'main' module in ''

Here the error message is telling you that the place where the Python program should begin (i.e. it’s “main” entry point) can’t be found in the filename '', which is not a filename at all.

Regardless of the build system you use, the problem you’re seeing is the same both times: you created a new tab and typed some code into it, but you didn’t save the file to disk first. Hence it doesn’t have a name on disk, and the Python interpreter doesn’t know what it’s supposed to be running.

In both cases, the solution to the problem is to save the file before you run your code. For a brand new file, you must always do this once to give the file a name on disk. Afterwards you need to do it to make sure that the file on disk is up to date, or else the Python interpreter is going to run old code.

For the latter case, the Tools > Save all on build option (which defaults to being checked) will make sure that all unsaved files are saved before a build happens. This is the recommended setting in the general case, but it doesn’t save files that don’t already have a name on disk.

This video discusses this problem and the fix; the link takes you directly to the explanation of this particular problem:

0 Likes

#3

Thanks so much OdatNurd
I saved the file and it lets me run the build in just Python but I’m supposed to be doing it in python3. When I choose Tools - Build System - Python3 and then I get:

[WinError 2] The system cannot find the file specified
[cmd: [‘python3’, ‘-u’, ‘C:\Program Files\Sublime Text\pythoncode1’]]
[dir: C:\Program Files\Sublime Text]
[path: C:\Python3.9.1;C:\Program Files (x86)\VMware\VMware Workstation\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Users\Local User\AppData\Local\Programs\Python\Python310\Scripts;C:\Users\Local User\AppData\Local\Programs\Python\Python310;C:\Python3.9.1\Scripts;C:\Python3.9.1;C:\Users\Local User\AppData\Local\Microsoft\WindowsApps]
[Finished]

The book I’m following is “Python Crash Course 2nd edition” it says to have Python run the correct version (Python3) by configuring sublime Text to use the correct version when running my programs.
Asks me to go to Tools - Build - System - New build and enter
{
“cmd”: [“python3”, “-u”, “$file”],
}

Says “this code tells sublime text to use your system’s python 3 command when running python program files. Save the file as python3 in the default director that sublime text opens when you choose to save.”

I’ve gone ahead and done all that and still receive the above error. When I save the build it saves to
C:\Users\Local User\AppData\Roaming\Sublime Text\Packages\User

0 Likes

#5

On windows Python 3 is named python ; it’s only MacOS and Linux that use python/python3 naming. Your error there is likely caused by the fact that there’s no such executable python3.exe for it to find (hence file not found).

You may want to run your code with the version that’s using python and run a program like:

import sys
print(sys.version)

To see what version of Python you have. Though, based on your diagnostic output above:

The version of Python you’re using is quite likely 3.9.1.

0 Likes

#6

Oh my gosh yes that was correct.

When I do that I get 3.10.1 and that was the issue I didn’t know the build for Python3 was MacOS… how intuitive :slight_smile:

1 Like

#7

Thank you very much!

0 Likes

#8

It looks like you are using ST 3. There is ST 4 btw, which uses py and it will auto fix your issue.

0 Likes

#10

I believe I downloaded this one image

0 Likes

#11

Hmm… ST 4 on Windows shouldn’t use python3 by default.

0 Likes

#12

I think the book even said if I have the latest version of python and I did, that it should not require making a new build. I just didn’t know python3 on sublime was for macos/linux and python was for windows.

0 Likes

#13

On Windows, it invokes py.

0 Likes

#14

Based on how core Sublime has only a single build system but in the original post it’s visible that there are at least two (since they do different things) I would guess that at some point an extra build was put in place.

Possibly this is because of an outdated book, or possibly because of all of the advice telling people to create new build systems in order to solve problems.

0 Likes

#15

FWIW, the book he has was published in 2019. There is also a 2015 edition which costs more on Amazon.

0 Likes

#16

Is there a better python book to get? :slight_smile:

0 Likes