Is Python interpreted or compiled? Both, in a specific order. The standard implementation, CPython, first compiles your source code to bytecode and then interprets that bytecode on a virtual machine. So Python is not a purely interpreted language, and it is not compiled to machine code ahead of time the way C is.
The label "interpreted language" is really a statement about the usual implementation, not about the language itself. Python the language has several implementations, and some of them compile code to machine instructions while the program runs. This article shows what actually happens when you run a script, how to look at the bytecode yourself, and why the distinction matters for speed.
.pyc files and __pycache__ come fromWhen you run python app.py, CPython performs these steps in order:
Step 2 is real compilation, but the target is bytecode, not the machine code of your CPU. Step 3 is interpretation: the virtual machine reads each bytecode instruction and carries it out. That is why the common summary is "compiled to bytecode, then interpreted".
Python is called interpreted because you never run a separate compile step by hand. You type python app.py and it just runs, and in the interactive prompt each statement is compiled and executed immediately. Compilation happens automatically and invisibly, so from the outside it feels like direct interpretation.
Compare this with a classic compiled language:
| Aspect | C or Go | Python (CPython) |
|---|---|---|
| Build step | Required, produces a native executable | None visible, compiles to bytecode on the fly |
| What runs | Machine code on the CPU | Bytecode on the Python virtual machine |
| Type checks | Mostly at compile time | Mostly at run time |
| Typical speed | Fast | Slower for CPU-heavy loops |
| Portability | Rebuild per platform | Same source runs anywhere CPython runs |
The standard library includes dis, which prints the bytecode of any function. This proves that compilation happens.
The output looks like this (the exact instruction names change between Python versions):
Each line is one virtual machine instruction. You can also call the compiler directly, which is what exec and eval use under the hood:
Bytecode is an implementation detail of CPython. It is not a stable format and it changes between versions, so never write code that depends on it.
.pyc files and __pycache__ come fromWhen you import a module, CPython saves the compiled bytecode in a __pycache__ folder as a file such as utils.cpython-313.pyc. The next import skips parsing and compiling as long as the source file has not changed. The file name includes the interpreter version because bytecode from one version does not run on another.
Two details are worth knowing:
.pyc files..pyc file speeds up start-up, not execution. The code runs at the same speed whether it came from cache or was freshly compiled.You can precompile a whole tree with python -m compileall src/, which is useful when building a deployment image.
Because Python is a language and not one program, different implementations make different choices.
| Implementation | Approach |
|---|---|
| CPython | Bytecode interpreter, the reference implementation |
| PyPy | Interpreter with a just-in-time (JIT) compiler that produces machine code for hot loops |
| Cython | Translates Python-like code to C, which you compile to a native extension |
| Nuitka | Compiles Python programs to C and then to native executables |
| MicroPython | Compact bytecode interpreter for microcontrollers |
CPython itself is moving in this direction slowly. Python 3.13 added an experimental JIT compiler that is off by default and has to be enabled when CPython is built, and the 3.14 release builds on that work. Treat it as experimental and do not rely on it for production performance yet.
Because Python decides many things at run time, it pays a cost per operation: each addition must check the types of its operands. That is why pure Python loops are slower than the same loop in C. The usual fixes are to use libraries whose inner loops are native code, such as NumPy, to choose better algorithms, or to try PyPy for long-running pure Python programs.
It also affects when errors appear. A syntax error is found during compilation, before any line runs. A NameError or TypeError is found only when that line actually executes:
Static type checkers such as mypy or pyright can catch many such problems earlier, without changing how Python runs.
Not in the sense of C or Rust. CPython compiles source to bytecode automatically, but it does not produce a standalone native executable. Tools such as Nuitka or PyInstaller can package a program for distribution.
No. The compile-to-bytecode step is built into the interpreter. You only need a C compiler when you install packages that have to build native extensions from source.
Each bytecode instruction is interpreted and operands are type-checked at run time, so there is more work per operation. Native libraries and better algorithms usually close the gap.
Yes. Use dis.dis(function) to print the bytecode, or look at the .pyc files in __pycache__.
Python is both compiled and interpreted. CPython compiles your source to bytecode and then interprets that bytecode on a virtual machine, caching imported modules as .pyc files. Whether a program counts as interpreted depends on the implementation: PyPy adds a JIT, and tools such as Cython and Nuitka produce native code. For everyday work, remember that the compile step is automatic and that run-time type checks are the main cost.