Part 01 / Topic 5 of 7
How the interpreter works
An interpreter is a program that reads your code and runs it. When you run python hello.py, three steps happen:
hello.py ──compile──▶ bytecode ──run──▶ PVM (Python Virtual Machine)
(source) (.pyc) (runs the instructions)
- Compile: Python turns your source code into bytecode (simple instructions, not machine code).
- Cache: For imported modules, bytecode is saved as
.pycfiles inside a__pycache__folder. Next time, Python skips compiling if the file has not changed. - Run: The PVM reads the bytecode and does the work.
The standard Python you download is called CPython (written in C).
Real-world example: Peek at the bytecode of a tiny function with the dis module.
(import loads a module, Part 7; def makes a function, Part 5. Just read along for now.)
import dis
def add(a, b):
return a + b
dis.dis(add)
# Output (Python 3.13, may look a little different in other versions):
# 3 RESUME 0
#
# 4 LOAD_FAST_LOAD_FAST 1 (a, b)
# BINARY_OP 0 (+)
# RETURN_VALUE
import importlib.util
# Where would Python cache the bytecode for a module named shop.py?
print(importlib.util.cache_from_source("shop.py"))
# __pycache__/shop.cpython-313.pyc (the number matches your version: -314 on 3.14)
| Word | Meaning |
|---|---|
| Source code | The .py file you write |
| Bytecode | Low-level instructions made from your code |
.pyc |
A file that stores bytecode |
__pycache__ |
Folder where .pyc files are kept |
| PVM | The engine that runs bytecode |
| CPython | The main Python implementation |
You never need to edit
.pycfiles. It is safe to delete__pycache__; Python makes it again.
🔍 Going deeper: Bytecode is a CPython detail. It changes between versions, so a
.pycfrom 3.12 is not used by 3.13 (that is why the file name hascpython-313). Your main script is compiled fresh each run; only imported modules are cached. Thedisoutput above also changes between versions (3.12 shows twoLOAD_FASTlines instead of oneLOAD_FAST_LOAD_FAST). 3.13 added two experimental extras. They are separate builds, not switches in the normal Python: a "free-threaded" build without the GIL (the lock that lets only one thread run Python code at a time), installed aspython3.13t, and a JIT compiler (turns hot bytecode into machine code), added when Python is built with--enable-experimental-jitand still off by default. In 3.14 the free-threaded build is officially supported (PEP 779), but it is still not the default.
🧪 Quick quiz — answer from memory, then check.
- What are the three steps when you run
python hello.py? - Is it safe to delete the
__pycache__folder? - What is CPython?
Show the answers
- Compile the source to bytecode, cache imported modules' bytecode as
.pycfiles, and the PVM runs the bytecode. - Yes — Python simply makes it again.
- The standard Python implementation (the one you download), written in C.
Done here? The practice set for Part 1 — 6 exercises with solutions — is on the part page.