The Python interpreter is the program that reads Python code and runs it.
This page covers Interpreter in Python. For a language-agnostic introduction, see Interpreter.
The python Command#
When Python is installed, it adds a program to the machine that runs .py files. That program is the interpreter. It is the same thing invoked by the python command (or python3 on macOS and Linux). Running python main.py hands the file to the interpreter, which reads it and carries out each statement.
The standard Python interpreter is called CPython. It is the one downloaded from python.org and the one most projects use. For a beginner, “Python”, “the interpreter”, and “the python command” all point at the same thing.
Why VS Code Asks You to Select an Interpreter#
A single machine can have more than one interpreter. There may be a system-wide Python, a newer version installed later, and a separate one inside each project’s virtual environment. Each is a distinct interpreter with its own packages.
Because several can be present, VS Code needs to know which one to use for a given project. That is what selecting an interpreter does. When a project has a virtual environment, the interpreter to choose is the one inside .venv, so the code runs against that project’s own packages rather than the system-wide Python.
The selected interpreter is shown in the bottom status bar, and it is the one both the Run button and the terminal use.
⚠️ Mistakes
Confusing the interpreter with the code editor
VS Code is where Python code is written. The interpreter is what runs it. They are separate: VS Code can be open with no interpreter selected, and the interpreter can run a file with no editor involved at all.
Running against the wrong interpreter
If the interpreter shown in the status bar is not the one inside .venv, the program runs against the system-wide Python instead of the project’s virtual environment, and packages installed in the project appear to be missing. Select the interpreter inside .venv to fix it.
Assuming python always means the newest version
On macOS and Linux, python may point at an old version or not exist at all, which is why python3 is used there. The interpreter that actually runs is whichever one the command resolves to, or the one VS Code has selected, not necessarily the newest installed.
📚 Resources
- Python Setup and Usage (external link), Python.org
- CPython (external link), Wikipedia