Sublime Forum

Beginner Coder Needs Help With Build System Error

#1

I’m just starting to learn python so I don’t know much about this system.
Every time I try to run the code with ‘ctrl b’ it says “No build system”. What does this mean and how do I fix it?
Thanks

0 Likes

#2

That’s an indication that Sublime doesn’t know how to build the file that you have selected. Generally that would mean that you might be using a type of file that it doesn’t understand, but since it supports Python by default your problem might be that it doesn’t know that the sort of file you’re trying to run is a Python file.

If that’s the case, saving the file and ensuring it has an appropriate extension (e.g. py) may help; the bottom right of the window tells you what sort of file Sublime thinks you’re editing; it should say Python there.

0 Likes

#3

My JavaScript file also has the same problem.
I saved it as a .js file but it still said “No build system”.
Pls help!:sweat:

0 Likes

#4

Sublime doesn’t ship with a way to run a JavaScript program by default, so that’s something that you would have to set up yourself. To do that you need to create a sublime-build file that tells Sublime what to do.

This is a particularly large topic (you can find documentation here), but in short you need to know how to manually do what you’re trying to do from a terminal in order to tell Sublime how to do it for you.

For example, one way to run JavaScript outside of the browser is to use NodeJS. When this is installed, you can use the node command from a terminal to execute a JavaScript script, e.g. node my_file.js.

Once you set up NodeJS and verify that you can run this command from a terminal and have it execute your program properly, you can proceed with setting up Sublime to run that command for you. To do that you would select Tools > Build System > New Build System... from the menu, which will open a new tab with a sample default build system in it that looks like this:

{
    "shell_cmd": "make"
}

shell_cmd is the command that you would execute in the terminal to run the command (in this example that’s the make command), so you would modify it to look something like this:

{
    "shell_cmd": "node \"${file}\"",
    "selector": "source.js"
}

This says to execute the program node and to pass to it the full name of the file that you’re currently editing, so that it runs the file that you’re working on. The second line tells Sublime that this is the build system applies to JavaScript source files.

If you save the above in the location that Sublime will default to as JavaScript.sublime-build, you’ll notice that the Tools > Build System menu now has an entry in it named JavaScript (it’s based on the name you give the file). From here you can select that build system and then run a build by selecting Tools > Build or pressing the key associated with it.

Alternatively, since the build knows that it’s for JavaScript files, you can set the build system to Automatic (it may already be set that way) and Sublime will automatically use this build for JavaScript files without your having to do anything else.

The most common pitfall with build systems is that whatever you put into shell_cmd needs to be something you can enter into a terminal and have it work. This generally requires you to either ensure that the location of the command you’re trying to execute is in the PATH environment variable on your system, or specify the full filename including path in the name of the command to execute. If it doesn’t work in the Terminal, it’s not likely to work in Sublime either.

1 Like

Building an ActiveXObject in JS
#5

I did that, it says “Build Finished” only in Python, but doesn’t run my code. It only shows:

0 Likes

#6

That is a symptom of the thing I mentioned above; whatever command that the build wants to execute (in this case python) needs to be available on your system and on the PATH so that it can be executed anywhere.

The error message you’re seeing indicates that either your Windows machine doesn’t have Python installed, or it’s installed but not on the PATH; so when Sublime asks Windows to run it, Windows doesn’t know what to do because it can’t find it.

0 Likes

#7

Do you need to like install Python & Pygame to run Sublime Text Python games?|

0 Likes

#8

Yep, I’m afraid so. Sublime ships with a Python interpreter but it’s embedded inside of Sublime itself for use in the Sublime Plugin system and as such is not available for you to run arbitrary code with.

0 Likes

#9

I have now installed python, and during the installation I ticked the box that said install on PATH, but it’s still showing the same error. What is the PATH and how do I fix this?

Thanks

0 Likes

#10

Whenever you tell your computer to run a program (be it Windows, MacOS or Linux), the first step it takes is to find the program that you told it to execute. If you give it a specific name of a file, like C:\Program Files\Python36\python.exe, then it looks in exactly that location for that thing. On the other hand, if you just said python, then it has to figure out what that actually is.

Since there are an arbitrarily large number of potential locations where a program could possibly be, instead of performing an exhaustive search for a program every time you try to run it the system has the concept of something called a PATH, which is a list of directories on your computer where it will look for programs.

How you set the PATH depends on the operating system that you use, as well as the version of that operating system. So if you need to fiddle it the best bet is to do a quick google for how to do it for your specific operating system and version.

That said, if you ticked the box to tell it to update the path during the Python install, then you’re already money ahead. If you had Sublime running when you installed Python, you might need to quit and restart Sublime in order for it to pick up the change.

All else being equal, if you open a fresh command prompt/terminal you can use the where command on Windows or the which command on Linux/MacOS in order to see if the system knows about a program and if so, where it is. If this command gives you a location, it knows where the program is and it should work from Sublime; if you get an error or no response, then the folder that contains the program will need to be added to the path.

For example, on WIndows 10, you either get told the exact location of what the system would run (the first thing it found), or you get an informative message telling you that it didn’t find anything:

C:\Users\micro>where python
D:\Program Files\Python36\python.exe

C:\Users\micro>where some_program
INFO: Could not find files for the given pattern(s).

On Linux and MacOS, the command tells you where the first matching command is if it found it, or nothing at all if it didn’t, leaving you to infer that it could not be found:

tmartin:dart:~> which python
/usr/bin/python
tmartin:dart:~> which some_program
tmartin:dart:~> 
tmartin:tmac:~\> which python
/usr/bin/python
tmartin:tmac:~\> which some_program
tmartin:tmac:~\> 
2 Likes