Home / Blog /
How to code in Python on Sublime Text
//

How to code in Python on Sublime Text

//
Tabnine Team /
6 minutes /
August 12, 2021

Sublime Text Editor has been around since 2008 and has remained one of the most intuitive, free, and feature-packed code editors on the market. It’s great for new and seasoned developers alike, with features like multi-tab select, git integration, key bindings, file patterns, and a native command-line interface to make your workflow more efficient. On top of this, visual customizability allows the developer to create, import, and edit Sublime’s interface themes and color schemes.

By default, you can use it for any programming language, but its Python support is considered one of the best. Why? Because it’s written in C++ and Python. You might even say that Sublime Text is the best code editor to understand Python because it’s part Python.

But why, exactly, should you use Sublime Text for Python development? 

Why use Sublime Text for Python development?

It only takes three words to sum up the awesomeness of Sublime Text for Python: speed, interface, and customization.

Speed

Sublime Text is super fast. Unlike other IDEs that may take a bit of time to boot up and may bombard you with a few welcome messages and multi-tabs of text about the editor each time you boot it up, Sublime Text just opens.

Not only that, it opens and leaves exactly where you left off, including unsaved changes and code that may have been lost with any other editor. In a way, it’s like you never left. So there’s no worry about a low laptop battery or panic when Windows randomly forces you to restart midway through your work. You can close Sublime Text safely and know that everything will return intact and without any glitches.

Interface

Sublime Text’s interface is one of the cleanest interfaces for a code editor. With many IDEs, you’re bombarded with options galore, with side and bottom panels that often take up screen real estate. Sublime Text’s beauty lies in its minimalist approach, showing only what is necessary, which gives you the space to focus on your code.

Opening up a new project won’t close your current project either. Instead, it opens a completely new window for you to arrange as you wish on your screen. The separation can come in handy when you’re referencing multiple codebases

Some IDEs and code editors only allow for one project at a time. Sublime Text preserves your open projects and keeps them separated from each other. You don’t need to worry about accidentally editing the wrong files when you’ve got more than a dozen files open.

Customization

Sublime Text comes with a core set of rich features such as key bindings, indentation preferences, spell checks, multi-select, and file patterns. The highlight of Sublime Text is the ability to extend the current functionality with a thing called Packages.

Packages can be anything, including plugins, syntax highlighting customization, menus, and code snippets. In a way, packages can be seen as extensions that are pluggable into Sublime to perform whatever task you want.

How to set up Sublime Text for Python development

Step 1: Download Sublime Text and set up Python on your computer

You can download Sublime Text at sublimetext.com. Once completed, run the .exe file to complete the installation process.

You also need to have Python set up on your computer. If you haven’t already done this, you can download Python from python.org. Select the version of your OS system and follow the installation instructions. If you’re on Windows, just run the .exe file and follow the wizard.

Step 2: Configure Sublime Text for Python

Sublime Text comes pretty complete and ready for you to code out of the box. However, if you want to leverage Sublime Text for Python, you should install and configure the integrated terminal.

Without further ado, let’s get to installing and configuring the Integrated Terminal.

Go to Tools > Command Palette.

 

Type in Install Package Control and select it from the dropdown that appears. This will install Package Control on your Sublime Text editor.

Python Sublime Text

 

If the installation went correctly, you’ll get a pop-up message like this:

 

The next thing to do is install Terminus. To do this, start typing in Package Control and select Package Control: Install Package from the drop-down list that appears. (If your search bar disappears, just get back into it by navigating to Command Palette again.)

Package control Sublime Text

 

This will give you a new drop-down list of available packages that you can install to enhance your Sublime experience:

 

Look for Terminus and select it.

Python in Sublime Text

 

This will download the package. Once completed, it will appear under Preferences > Package Settings > Terminus.

sublime for python

 

You can open up Terminus by opening up Command Palette again and typing in Terminus. Select Terminus: Open Default Shell in Panel. This will open up your command line.

The last thing to do is set the syntax to Python by opening up Command Palette again and then typing in Python. Select the Set Syntax: Python option. This will ensure that your highlighting is based on Python syntax, making it easier to read your code.

Sublime Text

 

Now all that’s left to do is run your first Python code. To do this, use your terminal as you would any Python project. In the example below, we have a simple “Hello world” Python script and used Terminus to run it.

Python hello tabnine Sublime Text

Top Sublime Text Packages for Python developers

Using Command Palette, you can install whatever packages you want to enhance your Python workflow. Here’s a short list of the top packages you need to get started.

1. Package Control

Package Control is your main hub for installing packages. You need to install this first before you can install anything. Once installed, you will have the option to select Package Control: Install Package. This will open up a list of available packages for Sublime Text.

From here you can install any of the dozens of packages available. Navigate to Command Palette > Package Control: Install Package and search for the package of your choice and have fun!

2. Tabnine for Sublime

Tabnine is the AI coding assistant that accelerates and simplifies software development while keeping your code private, secure, and compliant. It supports over 30 languages, including Python.

3. requirementstxt

requirementstxt is a handy plugin that provides syntax highlighting, and easy version management for your requirements.txt files. 

4. Anaconda

If you’ve played with requirementstxt and it’s not to your fancy, Anaconda is another good alternative. Anaconda turns your Sublime Text editor into a Python-ready IDE by including autocompletion, code linting, autopep8 formatting, McCabe complexity checker Vagrant, and Docker support.

5. AutoPEP8

AutoPEP8 is a package that will automatically format your Python code to PEP 8 style guide for you. This means with your chosen key binding, you can quickly lint spaces to the correct standard.

6. SublimeLinter

Linting is an automated checking tool that checks for style and potential errors in your code. SublimeLinter is a staple linting tool in Sublime Text that is highly supported and frequently updated to ensure that the latest standards are met.

Wrapping it up

Overall, Sublime Text is one of the fastest and most responsive free code editors available. When it comes to Python, you don’t need a large suite of packages to get started. Terminus is a handy package to have to give that IDE feel without the lag. 

Coding Python in Sublime Text is a no-frills experience. The minimalistic interface makes it a distraction-free area. In addition to this, the large ecosystem of packages ensures that your every development need is met. All you have to do is install it via the Command Palette.

Optimize your software development with Tabnine AI

 

Tabnine is the AI coding assistant that accelerates and simplifies software development while keeping your code private, secure, and compliant. Boost engineering velocity, code quality, and developer happiness by automating the coding workflow through AI tools customized to your team.

Try Tabnine Pro free for 90 days!

[cta_btn url=”https://www.tabnine.com/pricing/landing” label=”Start a free trial”]