TNS
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
NEW! Try Stackie AI
Python / Software Development

How To Use VS Code for Python (and Why You Should)

Why should you use VS Code for Python development? All the features, of course.
May 22nd, 2024 6:34am by
Featued image for: How To Use VS Code for Python (and Why You Should)
Feature image via Unsplash+.

Since I started my journey with Python, I’ve been working with nothing more than a Linux OS and a terminal window. Nano has been my editor of choice and it’s been fairly easy going. But there was always something bothering me: Nearly every developer I know uses an integrated development environment (IDE) to code.

That always surprised me because, when I was studying C++ in school way back when, I used that same combination of tools, partly because I couldn’t afford the software the instructor suggested.

On top of that, I didn’t have a machine running Windows, and Microsoft didn’t offer a version of their IDE for Linux.

That was a long time ago and things have changed considerably. I’m no longer constrained to the terminal window because there are plenty of GUI tools available for Linux, and some were created and distributed by Microsoft.

One of those tools is Visual Studio Code, which also happens to be one of the more popular IDEs on the market. In fact, VS Code comes in second on PYPL’s Top IDE Index behind Visual Studio, and has a 13.51% market share.

So I decided to give VS Code a try with Python and quickly discovered that it was a fantastic move.

But why? When a terminal window and nano were getting me by just fine, why would I bother with a more complicated GUI? Let me first talk about the why and then we’ll deal with the how.

Why You Should Use VS Code for Python

Essentially, it all boils down to features. Writing Python within the Linux terminal window (using nano) doesn’t really offer much. Sure, you do get syntax highlighting (so you can tell when you’ve left out a ” a ‘ or a ), but that’s about it. You don’t get automatic indentation and other helpful features found in an IDE.

Another big plus of using VS Code is the wealth of extensions available for Python. You’ll find extensions for debugging, indentation, environments, previews, Django, Intellicode (AI assistance), docstring generation, Jupyter Notebook support and much more. To access all of these features from the command line would require considerable work.

The truth of the matter is, you really won’t need any of these features until you’ve gone beyond the very basics of learning Python. At first, I would highly recommend sticking with a text-based editor and the Python interpreter. Because you’re dealing with rudimentary code, there’s no need for all the bells and whistles offered by VS Code.

However, as you gain more experience with Python, you might want to migrate to an IDE like VS Code.

With that in mind, let me show you how to get started with VS Code and Python.

What You’ll Need

I’m going to demonstrate this on Pop!_OS Linux, but you can install VS Code on macOS or Windows as well. For those two operating systems, the installation is as simple as downloading the installer file, double-clicking it and walking through the installation wizard.

For Linux, the process is a bit more challenging. Although you can download an installer file for APT and DNF package managers, you don’t receive automatic updates unless you download the latest version when it’s released and then reinstall.

With that in mind, let’s install VS Code on both Ubuntu and Fedora-based distributions.

Installing VS Code on a Ubuntu-Based Distribution

The first thing to do is to make sure that wget and gpg are installed on your machine. For that, issue the command:


Next, we download the official Microsoft GPG key:


We can now install the key with this command:


Create a new apt repository entry:


Install the necessary dependencies with this command:


Update apt:


Finally, install VS Code with the command:

Install VS Code on a Fedora-Based Machine

First, install the required key:


Create the dnf repository entry:


Update dnf with this command:


Install VS Code:


Once you have VS Code installed, open it from your desktop menu and walk through the user-friendly onboarding wizard.

Enable Python Support

The next thing to do is enable Python support. For that, click the Extensions icon in the sidebar (which looks like the small Tetris-y icon, and can be found near the middle of the bar). In the resulting menu, type python and wait for the results. Click the Install button associated with the official Python extension. It should be the top result (refer to the image below).

Installing Python support in VS Code.

Once the extension is installed, you can then scroll through the remaining results and install any other Python-related extensions you might want. With that taken care of, you can then open a folder on your machine (select File > Open Folder) that contains your existing Python code. Your files will be listed in the left sidebar. Open one of your files and and continue working with it. For example, I’ll open a file from my Typecasting tutorial. The code appears in the editor. I can then click the Run button (a right-pointing arrow found near the top-right of the window). A pane will open below the editor, and the code will run.

One additional bonus that I didn’t mention earlier is that VS Code provides quick access to all of the files found in your selected folder. You won’t have to remember the name of what you’ve created and open it manually. That’s a small addition that can make a big difference in efficiency.

If you’re starting to get the hang of Python, I’d highly recommend that you add an IDE like VS Code into the mix. You’ll enjoy the added power and efficiency.

Group Created with Sketch.
TNS owner Insight Partners is an investor in: Enable.
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.