Module 1 · Beginner · Getting started

How to install Python and set up VS Code

Install Python on Windows, macOS or Linux, check it works, and set up VS Code with the Python extension to run your first program. Step-by-step, with fixes.

By theprogrammers team · · 5 min read

Before you can write Python, you need two things on your computer: Python itself, which runs your code, and an editor, where you write it. This guide takes about 15 minutes and gets you from nothing to a working program.

We'll install Python on Windows, macOS or Linux, check that it works, set up VS Code (a free editor used by millions of developers), and fix the problems beginners hit most often.

Prefer not to install anything yet? You can try Python in the browser with Google Colab or an online Python editor. But installing it properly is worth it: you'll need it for real projects.

Step 1: install Python

Windows

  1. Go to python.org, open Downloads, and download the latest Python 3 release for Windows.
  2. Run the installer.
  3. If the installer shows a checkbox called Add python.exe to PATH, tick it before clicking Install Now. This is the step beginners most often miss.
  4. Wait for "Setup was successful" and close the installer.

Alternatively, search for "Python" in the Microsoft Store and install the latest version from the Python Software Foundation.

macOS

macOS may come with an old Python or none at all. Download the latest macOS installer from python.org and run it. On a Mac, the command is usually python3, not python.

Linux

Most Linux distributions already include Python 3. If yours doesn't, on Ubuntu or Debian run:

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

Step 2: check that Python works

Open a terminal:

  • Windows: press the Windows key, type cmd or PowerShell, and press Enter.
  • macOS: open Terminal from Applications › Utilities.
  • Linux: press Ctrl + Alt + T on most systems.

Then type the command for your system and press Enter:

SystemCommand
Windowspython --version or py --version
macOS and Linuxpython3 --version

You should see something like Python 3.13.5. The exact number doesn't matter, as long as it starts with 3.

Step 3: install VS Code

  1. Download Visual Studio Code from code.visualstudio.com and install it. The default options are fine. On Windows, ticking Add "Open with Code" action is handy.
  2. Open VS Code and click the Extensions icon in the left sidebar (four squares), or press Ctrl + Shift + X.
  3. Search for Python and install the extension published by Microsoft. It adds running, debugging and autocomplete for Python.

Step 4: write and run your first program

  1. Create a folder for your code, for example python-course in your Documents.
  2. In VS Code, choose File › Open Folder and pick that folder.
  3. Create a new file called hello.py. The .py ending tells VS Code it's Python.
  4. Type:
name = "Python"
print(f"Hello, {name}!")
print(2 + 3)
  1. Click the ▶ Run button at the top right of the editor. The output appears in the terminal panel at the bottom:
Hello, Python!
5

If you see that, everything works. 🎉

If VS Code asks you to select an interpreter, press Ctrl + Shift + P, type Python: Select Interpreter, and choose the Python version you installed.

Fixing common problems

ProblemCauseFix
'python' is not recognized as an internal or external command (Windows)Python isn't on PATHTry py instead. Or rerun the installer, choose Modify, and tick Add Python to environment variables
Typing python opens the Microsoft StoreA Windows shortcut is intercepting the commandInstall Python, or turn off the python.exe entries under Settings › Apps › Advanced app settings › App execution aliases
command not found: python (macOS/Linux)The command is python3Use python3 and pip3
VS Code shows no ▶ Run buttonThe Python extension isn't installed, or the file doesn't end in .pyInstall the Microsoft Python extension and save the file as .py
Old version shown, such as Python 2.7An older Python comes firstUse python3, or py -3 on Windows

Installing packages with pip

Python comes with pip, a tool that installs extra packages from PyPI, the Python Package Index:

python -m pip install requests

Use python3 -m pip on macOS and Linux. Writing python -m pip rather than just pip makes sure the package goes into the same Python you run. For real projects, install packages inside a virtual environment, as explained in the Python roadmap.

Key takeaways

  • Download Python 3 from python.org. On Windows, make sure it's added to PATH.
  • Check it with python --version (Windows) or python3 --version (macOS and Linux).
  • Install VS Code and Microsoft's Python extension, then run .py files with the ▶ button.
  • Install packages with python -m pip install <name>.

Practice

  1. Run python --version (or python3 --version) and write down the version you installed.
What you should see

Something like Python 3.13.5. Any version starting with 3 works for this course. If you see an error instead, check the "Fixing common problems" table.

  1. In hello.py, print your name, your city and the result of 365 * 24, the number of hours in a year.
Show the answer
print("Ahana")
print("Kanpur")
print(365 * 24)    # 8760
  1. Remove the closing bracket from one print line and run the file again. What happens?
Show the answer

Python stops with a SyntaxError that points at the line. Errors like this are normal. The guide to Python error messages shows how to read them.

Interview questions

What is pip?

pip is Python's package installer. It downloads packages from PyPI, the Python Package Index, and installs them, along with the packages they depend on. python -m pip install <name> runs it for a specific Python installation.

What is the PATH environment variable?

PATH is a list of folders the operating system searches when you type a command. If Python's folder isn't on PATH, typing python in a terminal gives a "not recognized" or "command not found" error, even though Python is installed.

What is a virtual environment, and why use one?

A virtual environment is a separate folder with its own Python and packages, created with python -m venv .venv. Each project gets its own versions of packages, so upgrading a package for one project can't break another.

What to learn next

  1. Learn the different ways to run code, including the interactive shell, in how to run Python.
  2. Then write your first Python program, line by line.