Sublime Forum

"No Build System" for Python 3

#1

I’m a novice in Python3 and Sublime Text and coding in general. I’ve searched through most of the topics on this but it still doesn’t solve my problem.

I’ve created a new build system for python3, which I copied from the textbook:
{
“cmd”: [“python3”, “-u”, “$file”],
“file_regex”: “^ []File "(…?)”, line ([0-9]*)",
“selector”: “source.py”
}

And when I tried to run the Hello_world program, ensuring that on Tools>Build System>python3 was selected. Yet when I 'build" it the bottom bar says “No build system” and nothing else showed up.

Please advise, and thank you so much for the time and help.

0 Likes

Python3 on Mac (Big Sur)
#2

sublime-build files are JSON files, but the content of the file that you’re using is not valid JSON because the double quote characters are the “fancy” curly-quotes that curve inward instead of being straight " characters, which is not valid JSON. Additionally the file_regex is broken because the " character after File is ending the string; you need to use \" inside of a string to represent a double quote character inside of the string itself.

When the sublime-build file is not valid JSON, Sublime can’t decode it properly. It doesn’t display any explicit error message when this happens, but when it tries to access the build information it can’t and as a result it says No build system in the status bar (which is technically correct but not overly helpful).

A fixed version would be something like this:

{
    "shell_cmd": "python3 -u \"$file\"",
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",

    "env": {"PYTHONIOENCODING": "utf-8"},

    "variants":
    [
        {
            "name": "Syntax Check",
            "shell_cmd": "python3 -m py_compile \"${file}\"",
        }
    ]
}

This is a duplicate of the Python.sublime-build that ships with Sublime, but altered to run python3 instead of python. If you replace the contents of the file created with this one, it should do what you want.

1 Like