Setting Your Python Version in Sublime-Text

Ahh…”Just right!”

MB
The Startup
2 min readJan 7, 2020

--

photo by Mercelo Gerpe at freeimages.com

Finding the right IDE is like stepping into a “The Three Bears” storybook. This one is too simple, this one is too complicated, this one is ‘Just Right’…except for the annoying fact that it’s using Python 2.7.

At least that was my issue with Sublime. I’ve tried other editors and they all work fine, but for some reason I like the look and feel of Sublime. I an attempt to rectify my issue, I of course turned to DuckDuckGo and found the internet was largely silent on an answer. After an hour of searching, messing with the program, and changing C++ build files, I finally hit those two keys “Ctrl+B” and my “F string literal” actually worked.

If you are in the same boat, let me save you some time and frustration.

First, if you are on a Linux machine or Mac, follow below. If you are running Windows, I’m sorry…

See which version of Python is running in Sublime-Text

Open Sublime, save a test file and run the following:

The output will be something like:

If you are running the version you want, congrats! If not lets fix it.

Find your Python path

Open up a terminal and run:

Your output will likely be /usr/bin/python2.7 or something similar. Now to find all the versions of Python on your system currently run:

In my case, this is:

and I get this mess:

Now if you are in the same boat, its probably time to learn about virtualenv. In my case, I’ve been lazy with this Ubuntu box and now I’m in this situation.

I want to run Python3.6 in my Sublime-Text application. To do this I need to change my python.sublime build file:

Open Sublime-Text and then select:

Now select PackageResourceViewer and this will install it.

Now we need to update the build file. Select the following:

Change the “shell_cmd”: “pythonX.X” to your desired python version. Be sure to change the “variants shell_cmd” to the same.

Save the file, re-run your test file and you should now see the correct version being run.

--

--

MB
The Startup

Husband, Father, Pediatrician & Informaticist writing about whatever is on my mind for today.