Sublime Forum

Having trouble with using my virtual environment in Python -- "no build" response

#1

I have a virtual environment with exe file here:

“D:\Learning Flask\Flask beginner tutorials\env\Scripts\python3.6.exe”

After following tutorials it seems I need to go to build system -> New build system

And then change the build config file as follows:
{
“cmd”: [“D:\Learning Flask\Flask beginner tutorials\env\Scripts\python3.6.exe”, “-u” “$file”],
“file_regex”: “^[ ]File "(…?)”, line ([0-9]*)",
“selector”: “source.python”
}

After doing so, I then save as “test”,
and then access the “build system” menu once again, and select the “test” build.
Next, I try to run an open Python script with Ctrl +b but I get a “no build system” in the gray bar at bottom of screen.

How am I doing wrong with the config file?

Thank you.

0 Likes

#2

The content of the sublime-build file needs to be valid JSON, but the build as you’ve outlined it above is not. As a result, when Sublime tries to load the build file, it fails, hence the No build system error.

The errors in your build are related to:

  • The path separators need to be either / or \\ because the \ character is for JSON escape characters, and things like \L are not valid JSON escapes; Windows supports / as a path separator, but if you want to use the other style you need to use \\ instead.

  • The " characters inside of the file_regex are closing the string when you don’t expect them to; in order to use a " character inside of a string, you need to use \" instead.

  • The items inside of the cmd list need to be separated from each other with commas, but the last two items are not.

Something like the following may work better:

{
  "cmd": ["D:\\Learning Flask\\Flask beginner tutorials\\env\\Scripts\\python3.6.exe", "-u", "$file"],
  "file_regex": "^[ ]File \"(...*?)\", line ([0-9]*)",
  "selector": "source.python"
}
1 Like

#3

Ah. That’s why those portions were highlighted in red. I thought it was part of some higlighting feature that I could just ignore the time being.

First I would like to really thank you for the detailed answer; I learned a lot.
I just have a question about file_regex and selector
What exactly are each of them doing?

Most tutorials are just copying and pasting and I am seeing some discrepancies among tutorials.

For example “selector” was also written as :

{

"cmd": ["/Users/<username>/virtEnv1/bin/python", "$file"],
"file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
"selector": "source.activate"
}
0 Likes

#4

The selector is used to detect what build system to use if the item in Tools > Build System is set to Automatic; it represents the scope for which a build system applies so that Sublime can choose the correct build.

Scopes in Sublime are a pretty big topic (this video on Scopes and Scope selectors may help in this regard) but in short they’re associated with the syntax definition that’s currently in use. The first item in any scope represents the type of the file, and that’s what’s used in build systems to associate then with file types. The first item you see in the popup that appears when you choose Tools > Developer > Show Scope Name is what you’d use to associate a build with a file.

The file_regex (and line_regex, when it appears) are used to detect errors in the output of a build, specifically the line, column, file and error message (or some subset, depending on the language in question). This powers the ability to jump to error locations through the Tools > Build Results menu items, as well the inline errors that are displayed by the show_errors_inline setting.

I have a video series on Sublime Build Systems that may shed additional light on how build systems work and how to use them, if you’re interested in more details.

0 Likes