Learning Center
Python

How to Set Up Visual Studio Code for Python

5 Feb 2025
Hostman Team
Hostman Team

Creating and debugging programs in Python is easier when using a specialized Integrated Development Environment (IDE). With an IDE, you can quickly and efficiently develop, test, and debug programs.

Visual Studio Code (VS Code) for Python provides full support for the language and offers a wide range of plugins and extensions. In this article, we will install Visual Studio Code on three operating systems (Windows, macOS, Linux) and set it up for Python programming, including the use of popular plugins.

Prerequisites
Copy link

To install and set up Visual Studio Code for Python, we will need the following:

  • A personal or work computer with Windows 10/11, macOS, or Ubuntu Linux distribution version 24.04 pre-installed. Alternatively, you can rent a dedicated server or a virtual machine with Windows Server 2016/2019/2022. If using regular versions of Windows, you can download your own ISO image in advance. You can also rent a server with Ubuntu.

Installing the Python Interpreter
Copy link

Before installing VS Code, we need to install the Python interpreter on all three operating systems — Windows, macOS, and Linux.

On Windows
Copy link

  1. Go to the official Python website and download the installer file. In this case, we will be installing Python version 3.13.1.

F0a25261 3828 4bc2 923d 786a97e670be (1)

  1. Run the installer file.
  2. You will have two installation options:
    • Install Now — This performs a full installation, including documentation files, the package manager pip, the tcl/tk library for graphical interface support, and standard libraries.

    • Customize Installation — This option allows you to choose which components to install.

We will use the full installation. Make sure to check the box next to the option Add python.exe to PATH and click Install Now. The installation process will begin.

Image7

  1. Once the installation is complete, the program will notify you that it has finished.

Image27

On macOS
Copy link

On macOS, the Python interpreter is pre-installed by default. You can verify this by running the following command in the terminal:

python3 --version

D4a7a3e0 283f 4b80 Bb4b 2324887d13ae

However, the installed version may be outdated. If necessary, you can install a newer version. To do this, we will use the Homebrew package manager. First, if Homebrew is not installed on your system, you can install it by running the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Next, you need to check which versions of Python are available for installation. Use the following command:

brew search python

In our case, several versions of Python are available:

Image22

Install the latest available version, Python 3.13, by running the following command:

brew install python@3.13

Check the Python version again:

python3 --version
python3.13 --version

Image5

As shown in the screenshot above, running the python3 --version still shows the old version (Python 3.9.6). However, the newly installed version (3.13) can be accessed using the command python3.13 --version. If needed, you can change the default Python version to the newly installed one. To do this, first get the full path to the newly installed Python interpreter using the following command:

brew --prefix python@3.13

Then, check which shell you are using:

echo $SHELL

Depending on the shell used, open the corresponding file for editing:

For bash or sh:

nano ~/.bashrc

For zsh:

nano ~/.zshrc

Add the following line at the end of the file:

export PATH="/opt/homebrew/opt/python@3.13/bin:$PATH"

Save the changes and reload the file:

source ~/.zshrc

Now, when you check the Python version, it will display the latest installed version:

python3 --version

Image26

On Ubuntu
Copy link

By default, Python is pre-installed on almost all Linux distributions, including Ubuntu. In the latest supported versions of Ubuntu, the current version of Python is installed:

python3 --version

Image16

However, if Python is not installed for any reason, you can install it by running the following command:

apt -y install python3

Installing Visual Studio Code
Copy link

You can install Visual Studio Code on your personal computer. You can also rent a dedicated or cloud server with Windows Server or one of the available Linux distributions. If the required distribution is not available in the list of offered images, you can upload your own.

We will cover the installation of Visual Studio Code on three operating systems: Windows, macOS, and Linux (Ubuntu 24.04 distribution).

For Windows
Copy link

Visual Studio Code supports installation on Windows 10 and Windows 11. It also supports Windows Server distributions, from version 2016 to 2022.

We will install it on Windows 10. 

  1. Go to the official website and download the installer.

Image15

  1. This will download an .exe installation file. Run the installer file. 
  2. On the first step, accept the license agreement by selecting the option "I accept the agreement".

Image18

  1. Next, the installer will prompt you to choose an installation location. You can choose the default path suggested by the installer or specify your own.

Image11

  1. If necessary, you can create a shortcut for the program in the Windows menu. If you don’t want to create a shortcut, select the option "Don’t create a Start Menu folder" at the bottom:

Image3

  1. The next step lets you configure additional options by ticking the corresponding checkboxes:
    • Create a desktop icon — creates a shortcut on the desktop for quick access to the program.

    • Add “Open with Code” action to Windows Explorer file context menu — adds the "Open with Code" option to the context menu when right-clicking on a file. This option allows you to quickly open any file directly in Visual Studio Code.

    • Add “Open with Code” action to Windows Explorer directory file context menu — similar to the above option but adds the "Open with Code" option to the context menu of directories (folders).

    • Register Code as an editor for supported file types — makes Visual Studio Code the default editor for certain file types (e.g., .c, .cpp, .py, .java, .js, .html files).

    • Add to PATH (require shell restart) — adds Visual Studio Code to the system’s PATH variable so it can be launched from the command line (cmd).

Image20

  1. Once all necessary options are set, Visual Studio Code is ready for installation. Click Install.

After the installation is complete, you can launch the program immediately:

Image12

For macOS
Copy link

  1. Go to the official website and download the installer:

Image33

  1. After downloading, you will have a ZIP archive. Inside the archive, you will find the executable file, which you need to extract to the "Applications" directory.
  2. On the first launch, the system will notify you that this file was downloaded from the internet and may not have vulnerabilities. Click Open to continue:

Image19

For Linux (Ubuntu)
Copy link

Visual Studio Code supports installation on Linux distributions such as Ubuntu, Debian, Red Hat, Fedora, and SUSE. You need a graphical desktop environment to install Visual Studio Code on Linux (GNOME, KDE, Xfce, etc.).

Let’s consider the installation of Visual Studio Code on Ubuntu 24.04 with the Xfce desktop environment. You can also install Visual Studio Code using Snapcraft.

  1. Go to the official website and download the installer for your Linux distribution. In our case, we need the .deb installer:

Image37

  1. Once the file is downloaded, open a terminal (console) and navigate to the directory where the file was downloaded (e.g., /root).

  2. To install, run the following command where code_1.96.2-1734607745_amd64.deb is the name of the downloaded file:

dpkg -i code_1.96.2-1734607745_amd64.deb
  1. During installation, a message will prompt you to add Microsoft repositories to the system. Select <Yes> and press Enter:

Image39

  1. Wait for the installation to complete.

  2. Once the installation is finished, you can launch the program from the applications menu (for distributions using Xfce, Visual Studio Code is available in the menu: ApplicationsDevelopment):

Image23

Adding Python Interpreter to PATH Variable in Windows
Copy link

If you haven't checked the Add python.exe to PATH checkbox during the Python installation on Windows, you need to manually add the full path to the interpreter to run Python from the command line.

To do this:

  1. Press Win+R, type sysdm.cpl in the Run window, and press Enter.
  2. In the window that opens, go to the Advanced tab and click on the Environment Variables button.

Image6

  1. To add a user-level variable, select the Path variable under User variables and click on Edit.

Image14

  1. Double-click on an empty field or click the New button.
  2. Enter the full path to the Python interpreter file. By default, the Python interpreter is located at the following path:
C:\Users\<Username>\AppData\Local\Programs\Python\Python313

For example:

C:\Users\Administrator\AppData\Local\Programs\Python\Python313

Image20 (1)

  1. After entering the path, click OK to save the changes.
  2. To verify, open the command prompt and type python. If the path to the interpreter is correctly specified, the Python console will open.

Image33 (1)

Setting Up Python Interpreter in Visual Studio Code
Copy link

In Windows
Copy link

Once Python is installed, you need to connect it to Visual Studio Code. To do this:

  1. Open Visual Studio Code and click the New File... button on the home page to create a new file. 

Image12 (1)

Alternatively, you can create a Python project in Visual Studio Code by clicking on Open Folder…, where you can select the entire project folder containing the files.

  1. Type any name for the file, use the .py extension, and press Enter.

Image21

  1. Save the file in any location. Ensure that the file name ends with the .py extension.

Image23 (1)

  1. Once the file is saved, the interface in Visual Studio Code will display a prompt at the bottom right, suggesting you install the recommended Python extension.

Image1

  1. To run Python in Visual Studio Code, you first need to select the Python interpreter. A button will appear at the bottom of the panel with a warning: Select Interpreter. Click on it.

Image11 (1)

  1. In the menu that appears, select Enter interpreter path… and press Enter.

Image24

  1. Specify the full path to the Python interpreter. By default, it is located at:
C:\Users\Administrator\AppData\Local\Programs\Python\Python313

where Administrator is your user account name. Select the file named python and click on Select Interpreter.

Image17

To test it, write a simple program that calculates the square root of a number:

import math

num = float(input("Enter a number to find its square root: "))

if num >= 0:
    sqrt_result = math.sqrt(num)
    print(f"The square root of {num} is {sqrt_result}")
else:
    print("Square root of a negative number is not real.")

In Visual Studio Code, to run the Python code, click the Run Python File button at the top-right. If the interpreter is set up correctly, the program will run successfully.

Image8

In macOS
Copy link

On macOS operating systems, the Python interpreter is automatically recognized. Simply create a new .py file as described in the Windows section above and run the program directly.

Image4

In Ubuntu
Copy link

Similarly to macOS, in the Ubuntu distribution, VS Code automatically detects the installed Python interpreter in the system. All you need to do is create a new .py file and run the program directly.

Image18 (1)

Recommended Extensions for Python in Visual Studio Code
Copy link

VS Code offers a wide range of Python extensions (plugins) that simplify the development process. Here are some of the most popular ones:

Pylance

Pylance provides code analysis, autocompletion, and IntelliSense support, making Python development more efficient and user-friendly. Key features include fast autocompletion, type checking, and IntelliSense support.

Image9

Jupyter

The Jupyter extension is a powerful tool for working with interactive notebooks directly in the editor.  It’s especially useful for data analysis, machine learning, visualization, and interactive programming tasks.

Image28

autoDocstring — Python Docstring Generator

autoDocstring is a popular extension that helps automatically generate docstrings for Python functions, methods, and classes. Docstrings improve code readability and serve as built-in documentation.

Image25

isort

isort is a tool for automatically sorting and organizing imports in Python code. You can configure it in Visual Studio Code to make working with imports easier and to improve code readability.

Image10

Conclusion
Copy link

This article covered the installation and setup of Visual Studio Code for Python development. Visual Studio Code offers full support for Python and provides the ability to extend its functionality through various plugins, making the coding process easier and more efficient.