Skip to main content

Setting Up Sublime Text 3 for Python (2 and 3) Development

This is the continuation of this tutorial: http://algidus.blogspot.com/2017/12/installing-python-3-and-2-in-windows-10.html

We will now set up Sublime Text 3 to run codes of both Python 2 and 3.

  • First Download Sublime Text 3: https://www.sublimetext.com/3
  • By Default, the "Build System" of Sublime Text 3 is set to "Automatic".
  • To change the "Build System", go to "Menu" Bar (Press "Alt" if it's not visible) and select "Tools" and "Build System". Then select "Python" from the options.
  • In the previous tutorial, we kept Python 3 as our default Python Version (By setting its path in the "Environmental Variables"). So, in Sublime Text 3, when you select "Python" in the "Build System", you'll be running the code in "Python 3".
  • Now we're going to add a Custom Build System for "Python 2".
  • To add a Build System for "Python 2", go to "Tools" in the menu and select "Build System" and then select"New Build System..." and paste the following code: [Assuming that your Python 2 was installed in "C:\Python27\"]
  • 
    {
        "cmd": ["C:/Python27/python", "-i", "-u", "$file"],
        "file_regex": "^[ ]File \"(...?)\", line ([0-9]*)",
        "selector": "source.python"
    }
    

  • Then, save the file as "Python2.sublime-build" [Typically in the "C:\Users\your_username\AppData\Roaming\Sublime Text 3\Packages\User" Folder.]
  • Restart Sublime Text 3.
  • Now you can run code in different versions of Python by changing the "Build System" before building the code.

    To check the version of Python where the code is being built, you can copy paste the following code, save it as anyname.py and build [Ctrl + B] or Tools > Build

    
        import sys
        print(sys.version)