November 2, 2024

How to install Python in VS Code and How to Debug and Install Packages in Virtual Environment

In this tutorial, we explain how to install VS Code (Visual Studio Code) and how to set up VS Code such that you can run Python code files or scripts in VS Code. This tutorial assumes that the user is using a computer running Windows. VS Code is an abbreviation for Visual Studio Code. It is a powerful program development environment. You can use VS Code to write and compile Python, C, and C++ code files. VS Code should not be confused with Microsoft Visual Studio. VS Code is a much more lightweight development environment compared to Microsoft Visual Studio. VS Code is very popular in the Robot Operating System (ROS) community.

More precisely, in this tutorial, we explain:

  • How to install VS Code
  • How to install Python in VS Code
  • How to set up a virtual Python environment in VS Code
  • How to install Python packages in VS Code
  • How to debug Python code in VS Code

Before we start with explanations, we need to explain the motivation for using Python in a virtual environment. Namely, virtual environments can be used to completely customize Python package installation. For example, let us say that you want to use two versions of the same package. The motivation for this can be for example the fact that and older version can only be used with some other older software packages. On the other hand, the new version should be used with some other packages. We can create two virtual Python environments. In one virtual environment, you can install the older version, and in another virtual environment you can install the newer version. These two Python virtual environments do not interfere with each other.

Also, VS Code is arguably one of the most popular IDEs and programming development environments for Python and C++. This motivates us to create this tutorial. The installation procedure is explained in the video shown below.