Tutoriel
Partie 3 — Installing Python and Setting Up VS Code Properly (2026 Step-by-Step)

Partie 3 — Installing Python and Setting Up VS Code Properly (2026 Step-by-Step)

Step-by-step guide to install Python and configure VS Code in 2026. Learn PATH setup, interpreter selection, virtual environments (.venv), pip, formatting with Black, and debugging so your Python projects run perfectly.

Python 13 Mis à jour 4 hours ago
Conseil : lisez d’abord les sections clés, puis essayez un QCM lié à la même notion pour valider votre compréhension.

3. Installing Python and Setting Up VS Code Properly

A lot of beginners lose time because Python is “installed” but not working in the terminal, or because VS Code runs the wrong interpreter. In this section, you’ll set up everything properly on Windows, macOS, and Linux: Python installation, PATH configuration, VS Code extensions, interpreter selection, virtual environments, formatting, and debugging — so you can code with confidence.

Goal: You should be able to run python --version (or py --version on Windows), then run a .py file inside VS Code without errors.

A) Install Python the Right Way

Python has two common commands depending on your system: python and python3. The important thing is that your terminal recognizes Python and returns a version like Python 3.12.x or newer.

1) Windows (recommended setup)

  1. Download Python (64-bit) from the official site.
  2. Important: during installation, tick “Add python.exe to PATH”.
  3. Complete the installation, then close and reopen PowerShell/Terminal.

Verify Installation (Windows)

py --version
python --version
pip --version
        

If python --version fails but py --version works, that’s normal on some Windows setups.

Common Windows issue: If you see “Python was not found”, it usually means PATH wasn’t set. Re-run the installer and enable the PATH option.

2) macOS

On macOS, the safest approach is installing Python via the official installer or a package manager. Then use python3 in the terminal.

Verify Installation (macOS)

python3 --version
pip3 --version
        

3) Linux (Ubuntu/Debian example)

Many Linux distributions already include Python. If not, install it via your package manager.

Install + Verify (Linux)

sudo apt update
sudo apt install python3 python3-pip python3-venv -y

python3 --version
pip3 --version
        

B) Install VS Code + Essential Python Tools

VS Code is one of the best editors for Python because it supports autocomplete, linting, formatting, debugging, and virtual environments. But you must install the right extensions.

VS Code

Install Visual Studio Code, then open it once to finish setup.

Python Extension

In VS Code Extensions, install: Python (by Microsoft). It adds interpreter selection, debugging, and more.

Recommended: also install Pylance (often installed automatically) for smarter autocomplete, and Jupyter if you plan to use notebooks.

C) Select the Correct Python Interpreter in VS Code

Many “it doesn’t work” problems come from VS Code using the wrong interpreter. Fix it once:

  1. Open your project folder in VS Code.
  2. Press Ctrl + Shift + P (or Cmd + Shift + P on macOS).
  3. Search: Python: Select Interpreter.
  4. Choose your Python version (preferably the one inside your project’s virtual environment if you have one).
Tip: In the bottom-right of VS Code, you’ll see the selected interpreter version. Always check it before running code.

D) Create a Virtual Environment (Best Practice)

Virtual environments keep dependencies clean and separate per project. This avoids conflicts and “works on my machine” issues. In 2026, this is considered standard practice even for beginners.

1) Create the environment

# Windows
py -m venv .venv

# macOS / Linux
python3 -m venv .venv
    

2) Activate the environment

# Windows (PowerShell)
.venv\Scripts\Activate.ps1

# macOS / Linux
source .venv/bin/activate
    

When activated, your terminal usually shows (.venv) at the start of the line. Then install packages safely inside the project:

pip install requests
pip freeze > requirements.txt
    
Pro workflow: create .venv inside each project folder, select that interpreter in VS Code, and keep a requirements.txt.

E) Configure Formatting (So Your Code Looks Professional)

Consistent formatting makes your code cleaner and easier to read. VS Code can format on save. A common modern formatter is Black.

Install formatter

pip install black
    

Enable “Format on Save”

  1. Open VS Code Settings
  2. Search: Format On Save
  3. Enable it
  4. Set formatter to Black (Python default formatter)
Result: every time you save, your code is automatically cleaned and formatted.

F) Run and Debug Python in VS Code (Properly)

You can run a Python file in two main ways:

  • Run Button (top-right) in VS Code
  • Terminal using python file.py

Create a file test.py with:

name = input("Your name: ")
print("Hello,", name)
    

To debug: click on the left of a line number to set a breakpoint, then press F5 or click Run > Start Debugging. Debugging helps you understand code behavior step-by-step.

Common issue: If VS Code can’t find packages you installed, it’s almost always the wrong interpreter selected. Select the .venv interpreter again.

G) Quick Checklist (So You Know Everything Is Correct)


Conclusion

Once Python and VS Code are configured correctly, learning becomes much easier. You avoid beginner traps, you keep your projects clean with virtual environments, and you write professional-looking code with formatting and debugging. In the next sections, you can focus on learning Python itself — not fighting your setup.