How to run Python from VS Code

Jugo Mobile
By
Jugo Mobile
Jugo Mobile is a platform dedicated to high-quality content in gaming, sports, and tech. Engage with high-quality content and connect with fellow enthusiasts and experts. Explore...
12 Min Read

Visual Studio (VS) Code offers Python development support that both professionals and hobbyists can appreciate. This article will provide practical knowledge on how to set up your Python environment and run and debug Python code, along with valuable and interesting additional features.

Setting up the Python environment

You will have to manually configure the Python interpreter on your computer before VS Code can use it. Here’s how to do it:

  1. Visit the official Python website.
    1712693538 712 How to run Python from VS Code
  2. Go to the Downloads page, choose your operating system version (Windows, macOS, or Linux, depending on the library), and click download.
    1712693538 891 How to run Python from VS Code
  3. Download and run the installer.
    1712693538 775 How to run Python from VS Code
  4. Open a terminal or command prompt.
    1712693538 707 How to run Python from VS Code
  5. Guy “python –version” and press “Enter”.
    1712693538 894 How to run Python from VS Code
  6. You should see the installed Python version on the screen.

If data science is your primary reason for using Python, consider downloading Anaconda and using Python. Anaconda comes with a Python interpreter and a multitude of specialized libraries and tools for data science.

For Windows users who want a Linux environment powered by Python, the Windows Subsystem for Linux (WSL) is another viable option. Opting for WSL also involves installing the corresponding extension. For more information about using WSL with VS Code, see the VS Code Remote Development documentation or the Working in WSL tutorial.

After completing these steps successfully, the Python libraries will be installed on your system and you will be ready to write code.

Installing Python Extension in VS Code

To properly use the Python environment in VS Code, you must also install the Python extension. Here are the additional steps to configure the extension in the IDE:

  1. Start VS code.
    1712693538 1 How to run Python from VS Code
  2. Click the “Extensions” icon in the activity bar.
    1712693539 708 How to run Python from VS Code
  3. Search for “Python” in the search bar of the Extensions view.
    1712693539 146 How to run Python from VS Code
  4. Find Microsoft’s Python extension on the Marketplace.
    1712693539 979 How to run Python from VS Code
  5. Click the “Install” button to add the extension to VS Code.
    1712693539 877 How to run Python from VS Code

After following these steps, you will have the following prerequisites for Python coding:

  • Python (version 3 or higher)
  • VS code
  • VS Code Python Extension

Debugging Python code in VS code

Debugging is an inextricable part of the coding process, so you’ll want to have Python’s debugging capabilities ready as soon as you start coding. Let’s go over the steps to debug Python within VS Code.

  1. Click in the left margin next to the line number where you want to add a breakpoint (for example, next to the printed statement).
    1712693539 567 How to run Python from VS Code
  2. Click the Debug icon in the activity bar at the side of the window.
    1712693539 601 How to run Python from VS Code
  3. Press F5 or click the green “Run and Debug” button.
    1712693539 277 How to run Python from VS Code
  4. Choose “Python File” as the debug configuration.

The debugger will stop at the breakpoint. You will have the opportunity to inspect variables, view the call stack, and execute commands in the debug console.

Setting up your Python interpreter

VS Code automatically detects and selects the Python interpreter if it exists on your system. However, you may need to change the interpreter if you work with multiple versions of Python or run virtual environments.

  1. Press Ctrl + Shift + P (or Cmd + Shift + P on macOS) to open the Command Palette.
    1712693539 443 How to run Python from VS Code
  2. Guy “Python: Select Interpreter” in the command palette and press “Enter.”
    1712693539 838 How to run Python from VS Code
  3. Choose the Python interpreter you want from the list.
    1712693540 351 How to run Python from VS Code

With this setting, VS Code will now use the manually selected interpreter.

Customizing the VS Code Python Environment

Customizing your Python development environment is a fairly easy task in VS Code. Additionally, it is invaluable for improving productivity, as an environment tailored to your needs will make writing code faster and more efficient and reduce frustration.

To do this, VS Code offers robust and easy-to-access customization features. Experiment with different settings and extensions to find the most suitable settings as you become more comfortable using the tool.

Let’s look at ways to adjust the environment to your preferences.

Change Python Linting Tool

Linting identifies and fixes stylistic and syntactic problems in source code that can cause errors. Unlike formatting, which only restructures the appearance of the code, linting also analyzes how the code executes and identifies errors that improper formatting can cause.

  • Open the command palette by pressing Ctrl + Shift + P.
  • Select “Python: Select Linter” to display a list of linters.
  • Choose a preferred linting tool from the list (such as Pylint, flake8 or Mypy).
  • Install the linting tool in your Python environment if prompted.

If the installation cannot continue, try running Visual Studio Code with administrator privileges or manually install linter with a pip command.

Linting will run automatically when you save a file if enabled. Any problems you detect will be displayed in the Problems panel and as a squiggly underline in the editor window. You can keep the linter enabled or disable it when it is no longer needed. Open the command palette (Ctrl + Shift + P) and select “Python: Enable/Disable Linting” to change the option.

Configure Python Black for formatting

Python Black is a code formatter that automatically changes your Python code to follow style conventions with a focus on readability and code consistency.

  1. Install Black in your Python environment using the command: pip install black. To install the Python extension for Visual Studio Code, press Ctrl + P, past the line “ext install ms-python.python” and press “Enter.”
    1712693540 34 How to run Python from VS Code
  2. Type Ctrl + or click the gear icon in the lower left corner and select “Settings [Ctrl+,]”To open the Settings menu.
    1712693540 935 How to run Python from VS Code
  3. In the search bar at the top of the Settings tab, type “format on save” and check the checkbox.
    1712693540 481 How to run Python from VS Code
  4. Search for “Python Format Provider” and select “Black.”
    1712693540 856 How to run Python from VS Code

When you open or create a Python file, write some code and save it (Ctrl + S), the Black formatter will automatically wrap this code. If for some reason Black is not working, your Python code may have some syntax errors. In that case, double check the code and try it again.

Customizing Python Snippets

Python snippets can be a useful tool for optimizing your code. Snippets are predefined or user-defined blocks of code that you can insert into your code. They make writing repetitive code patterns, such as loops or conditional statements, faster. Here are the steps to customize Python snippets in Visual Studio Code:

  1. Open the Extensions view by pressing Ctrl + Shift + X and search for “Python Snippets”.
    1712693540 551 How to run Python from VS Code
  2. Install a Python Snippets extension that suits your needs.
    1712693540 516 How to run Python from VS Code
  3. Start using the new snippets in your Python code by typing the snippet prefix and pressing “Tab” or “Enter.”

Visual Studio Code has built-in snippets for several programming languages. You can find and insert these snippets using IntelliSense (Ctrl + Space) or a dedicated snippet picker. Python snippets are available for download from the Visual Studio Code Marketplace.

Many Visual Studio Code Marketplace extensions include snippets. You can find them by searching for “@category:”snippets” in the Extensions view. Once you’ve found an extension you like and installed it, restart Visual Studio Code. The new snippets will be available in the text editor when it restarts.

Using integrated terminal

One of the powerful features of VS Code is the built-in terminal, which allows you to run various commands, including Python scripts, without leaving the editor. Use the built-in terminal to run Python scripts, manage packages, and interact with version control systems like Git while you work on your Python scripts.

Collaborating with Live Share

Visual Studio Code comes with a Live Share extension. This feature enables real-time, remote collaboration of developers. Live Share allows you to discuss Python projects with team members and participate in joint programming sessions. Plus, you can get instant feedback on your code from a supervisor or assistant. This feature improves collaboration and encourages learning as you can share ideas and best practices with your co-developers.

Using Jupyter notebooks

Python developers often work with Jupyter Notebooks (formerly IPython Notebooks). It is an open source documentation project that allows the combination of code, text and visualizations. The application contains documents with computer code and rich text elements such as paragraphs, equations, figures and links.

Visual Studio Code provides native support and help through Python code files for working with Jupyter Notebooks.

Additionally, the Python extension in VS Code allows you to create, edit, and run Jupyter Notebooks directly. This integration provides a more efficient workflow that may appeal to data scientists and researchers who typically rely on Jupyter Notebooks.

Testing with Python functions

Knowing that your code behaves as expected gives you essential peace of mind. Prevents errors from accumulating while you code. This way, debugging won’t become more cumbersome as the code matures. VS Code supports different Python testing frameworks, including the popular unittest or pytest.

Take advantage of built-in testing features to quickly discover, run, and debug within the editor. Testing your development process allows you to catch bugs early, thus maintaining high code quality.

Execution through the Python interactive window

The interactive Python window in VS Code allows you to run code snippets and display the results visually. This feature helps you experiment with new ideas, explore libraries, or quickly test small code. While working on your Python projects, consider using the interactive window to get deeper insight into the behavior and performance of your code.

Python made easy

If you’ve made it this far, you’ll know how to run, debug, and customize Python code in VS Code as you see fit. VS Code is a powerful, versatile, and reasonably beginner-friendly Python development environment that accommodates various coding styles.

Do you run Python in VS Code regularly? Which Python customization in VS Code do you find most useful? Let us know in the comments section below.

TAGGED:
Share This Article
Follow:
Jugo Mobile is a platform dedicated to high-quality content in gaming, sports, and tech. Engage with high-quality content and connect with fellow enthusiasts and experts. Explore the latest trends and innovations in our vibrant community. Join us and experience the future today!
Leave a Comment
Grow your brand and reach a larger audience. Advertise with us today and get noticed by thousands.
© 2025 Jugo Mobile. All Rights Reserved.