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.
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.
Before installing VS Code, we need to install the Python interpreter on all three operating systems — Windows, macOS, and Linux.
Go to the official Python website and download the installer file. In this case, we will be installing Python version 3.13.1.
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.
Once the installation is complete, the program will notify you that it has finished.
On macOS, the Python interpreter is pre-installed by default. You can verify this by running the following command in the terminal:
python3 --version
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:
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
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
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
However, if Python is not installed for any reason, you can install it by running the following command:
apt -y install python3
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).
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.
.exe
installation file. Run the installer file. 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).
After the installation is complete, you can launch the program immediately:
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.
Go to the official website and download the installer for your Linux distribution. In our case, we need the .deb
installer:
Once the file is downloaded, open a terminal (console) and navigate to the directory where the file was downloaded (e.g., /root
).
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
During installation, a message will prompt you to add Microsoft repositories to the system. Select <Yes> and press Enter:
Wait for the installation to complete.
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: Applications → Development):
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:
sysdm.cpl
in the Run window, and press Enter.C:\Users\<Username>\AppData\Local\Programs\Python\Python313
For example:
C:\Users\Administrator\AppData\Local\Programs\Python\Python313
python
. If the path to the interpreter is correctly specified, the Python console will open.Once Python is installed, you need to connect it to Visual Studio Code. To do this:
Open Visual Studio Code and click the New File... button on the home page to create a new file.
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.
Type any name for the file, use the .py
extension, and press Enter.
Save the file in any location. Ensure that the file name ends with the .py
extension.
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.
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.
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.
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.
VS Code offers a wide range of Python extensions (plugins) that simplify the development process. Here are some of the most popular ones:
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.
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.
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.
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.
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.