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.
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)
- Download Python (64-bit) from the official site.
- Important: during installation, tick “Add python.exe to PATH”.
- 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.
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.
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:
- Open your project folder in VS Code.
- Press
Ctrl + Shift + P(orCmd + Shift + Pon macOS). - Search: Python: Select Interpreter.
- Choose your Python version (preferably the one inside your project’s virtual environment if you have one).
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
.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”
- Open VS Code Settings
- Search: Format On Save
- Enable it
- Set formatter to Black (Python default formatter)
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.
.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.