Hello! My name is Caleb, and I’ve recently switched careers from plumbing to IT due to tearing both my shoulders in the trade. I’m trying to learn Python programming currently along with Linux/Bash. I’m studying Python through a book called, “Python Crash course”, and the book suggested downloading Sublime Text. Once I started testing it out my scripts weren’t running because I was using Python instead of Python 3. Once I figured that out I’m still getting an error message saying, “python3: can’t open file ‘/opt/sublime_text/$file_basename’: [Errno 2] No such file or directory”. I’ve been very frustrated these past few days just trying to get any scripts to work. If anyone has the time to answer my question and or potentially mentor me it would change my world!!!
Setting up Sublime to run python
All else being equal, if you see advice anywhere online or in a book that tells you that you need to do something special in order to execute Python code in Sublime Text, it is most likely wrong in a fun variety of ways.
This is a bit of a generalization of course because setups differ, etc, but the more common problems that get reported are people using badly outdated advice and actually interfering actively with things that would have otherwise worked.
In your particular case it’s hard to say what the issue would be without seeing the contents of the sublime-build
file that the book told you to create, but $file_basename
is not a valid variable in a build system; it would be $file_base_name
.
However, the fact that you’re seeing it in the error output is suspicious because all variables, wether valid or not, are expanded out when builds run, even if they expand out to an empty string as a result of not existing.
You most likely want to be using Sublime Text 4 and not an older build of Sublime Text 3; ST4 has a Python.sublime-build
that executes Python 3 on all platforms (which is why the mention above that most advice on the internet is either outdated or flat out wrong in some fashion).
It’s also worrying that the file that it’s trying to run is in /opt/sublime_text
; generally speaking it’s not a good idea to store your files inside of the installation folder of any Software (including Sublime) because upgrades are frequently done by removing and replacing the folder, which is a recipe for losing your work.
If you can provide the contents of the sublime-build
file that you’re using, we should be able to narrow in on your problem for you and help you out.
For what it’s worth, my YouTube Channel has a variety of tutorials on it for Sublime, which includes a series on build systems and how they work that might also be of assistance in knowing how all the bits and pieces fit together.