Run Python 3.x Natively within Sublime Text 3 (On Windows 10)
The third tutorial on our series on Learning Python and Flask Fast. Here we focus on running the Python interpreter within Sublime Text 3. However, these instructions should work equally well for Sublime Text 2 and 3.
Heads-up: Replace “x” with Your Minor Release Version
The examples here use “x” as a placeholder for your Python 3 version. Just replace “x” with the second digit of the version (e.g., 3.5
or 3.7
) of your Python install.
Update
SublimeText 3 may be able to detect the path of Python 3.x if it’s installed. Restart your PC and reopen Sublime to see if it works.
The second part of this series shows you how to run Python 3.x scripts within Sublime Text 3. But before you begin, Sublime needs to know where you’ve installed Python!
- Go here:
C:\%AppData%\Sublime Text 3\Packages\User
- (a) Create a file called
Python3x.sublime-build
.Quick Tip
You can create this file by right mouse clicking in the folder -> New -> Text File. Just be sure to remove the “.txt” extension.
- Save the file. This will add a context menu item called
Python3x
within SublimeText - Open Sublime and create a file called hello_world.py with the following:
print("Hello World")
- Within Sublime context menu navigate to: Tools -> Build System -> Python34
- Now press CTRL b.
{
"cmd": ["c:/Python3X/python.exe", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
And that’s it! You will see your Python script running within Sublime. This file will now be associated with Python 3.4 and Sublime will run it on the CTRL b key press!