how to configure sublimetext for python 3 development

How to configure SublimeText3 for Python 3 development

how to configure sublimetext for python 3 development
Screenshot of SublimeText3 and Python 3 development

This post outlines the steps needed to configure SublimeText3 for Python 3 development. On many Linux distributions such as OpenSUSE Tumbleweed, SublimeText3 uses an older Python version 2 by default. To fix this, open SublimeText3 and do the following steps:

  • Go into Package Control
    Preferences > Package Control
    Shortcut: Ctrl + Shift + P
  • Chose option Package Control Package
    Type prv into the search field and chose
    Package Resource Viewer Open Resource
    Press ENTER
  • In the search field, type in python
    Type python once more and from the pop-up,
    chose: Python sublime-build

Python sublime-build

{
	"shell_cmd": "python3 -u \"$file\"",
	"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
	"selector": "source.python",

	"env": {"PYTHONIOENCODING": "utf-8"},

	"variants":
	[
		{
			"name": "Syntax Check",
			"shell_cmd": "python -m py_compile \"${file}\"",
		}
	]
}

As you can see by the above output, I have changed the first occurrence of the word python (top line) to python3 and saved the file. After that, I was able to run this code by pressing Ctrl + b

import matplotlib.pyplot as plt 
import numpy as np

percent_result = [12, 42, 20, 18, 8]
ssub = ['Vienna', 'Berlin', 'Toronto', 'Vancouver', 'Victoria']

plt.pie(percent_result, labels = sub, autopct = '%1.0f%%')
plt.show()

The above code generated this image graph:

linux macos sublimetext3 use python 3

Ubuntu

Sometimes, it’s best to evaluate what we want to do and chose an operating system that fits our needs. If developing Python software is important, then I recommend to use Ubuntu as it defaults to Python 3 upon installing. Visual Studio Code or Codium will use the latest available version of Python and the above steps won’t be necessary. OpenSUSE Tumbleweed is a great Linux distribution but needs the above listed setup to use the latest version of Python.

Thanks for reading and I hope that you will find this information useful when using SublimeText3 for writing Python scripts. Questions? Post below.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.