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!

  1. Go here: C:\%AppData%\Sublime Text 3\Packages\User
  2. (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.

    (b) Next, open the file with notepad and enter:
  3. {
        "cmd": ["c:/Python3X/python.exe", "-u", "$file"],
        "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
        "selector": "source.python"
    }
    
  4. Save the file. This will add a context menu item called Python3x within SublimeText
  5. Open Sublime and create a file called hello_world.py with the following: print("Hello World")
  6. Within Sublime context menu navigate to: Tools -> Build System -> Python34
  7. Now press CTRL b.

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!