Python Compiled or Interpreted?

Written by

Python interpreted or compiled?

When you start learning Python, one question eventually pops up: Is Python compiled or interpreted?

The short answer is: Both. But to understand how and why, you first need to understand what compiled and interpreted languages actually are.

What is a Compiled language?

A compiled language is one where the source code (the code you write) is transformed into machine code—the 1s and 0s understood by your CPU—before execution. This transformation is done by a compiler.

Examples: C, C++, Rust, Go

Key characteristics:

  • Compilation happens once before execution.
  • The result is a standalone executable.
  • Program execution is typically fast, because the CPU receives pre-compiled machine code.

What is an Interpreted Language?

An interpreted language is one where the code is executed line-by-line or instruction-by-instruction using an interpreter. There is no standalone executable and no separate, visible compile step.

Examples: JavaScript, Ruby, PHP

Key characteristics:

  • Execution happens “live” as the interpreter reads the code.
  • You do not manually compile anything.
  • Execution can be slower, since the interpreter must translate instructions on the fly.

So… Why Do We Use the python Command to Execute a File?

When you type:

python Hello.py

it may look like Python directly runs your .py file. But this is not what really happens.

What we think happens:

python Hello.py  --->  Python reads and executes your code directly

What actually happens:

  1. Your Python source code is compiled into bytecode
    (.pyc files stored inside the __pycache__ directory)
  2. The bytecode is sent to the Python Virtual Machine (PVM)
  3. The PVM interprets that bytecode and executes the corresponding machine instructions

In other words, Python code is first compiled, then interpreted. This is why the topic “python compiled or interpreted” is often confusing. The correct answer is that Python uses both steps, automatically and invisibly.

Python’s Bytecode and the Python Virtual Machine (PVM)

The Python compiler inside the interpreter converts your .py script into bytecode, which is a lower-level, platform-independent representation of your code.

This bytecode is then executed by the Python Virtual Machine (PVM).

Why bytecode?

  • Bytecode is faster to interpret than raw source code.
  • Python can cache it (.pyc) to skip recompilation next time.
  • It makes Python portable across operating systems.

CPython: The Compiler and Interpreter

The most common Python implementation—CPython—handles both:

  • Compilation (Python → Bytecode)
  • Interpretation (Bytecode → Execution via PVM)

Because CPython performs compilation on every run (unless bytecode is cached), it is slightly slower than languages that compile straight to machine code.

This dual behavior is why Python does not neatly fit into the “compiled vs. interpreted” categories.

Can Python Behave More Like a Fully Compiled Language?

Yes—by using different Python implementations.

For example:

  • PyPy uses a JIT (Just-In-Time compiler), making many programs run significantly faster.
  • Cython converts Python code to C for compilation.
  • Nuitka converts Python to optimized C++.
  • IronPython, Jython, and others integrate with different runtimes.

You can explore the full list of alternate implementations in the official docs:
https://docs.python.org/3/reference/introduction.html#alternate-implementations

Final Thoughts

So is Python compiled or interpreted?
The answer: Both. (And now you understand exactly why!)

Here’s a summary of how Python executes your Code:

  1. You run a .py file using the python command.
  2. Python compiles your code into bytecode automatically.
  3. That bytecode is executed by the Python Virtual Machine (PVM).

Understanding this flow helps junior programmers write more efficient code, debug performance issues, and choose the right Python implementation for their projects.

If you’re digging into Python’s internals, keep exploring! You’re already thinking like a real technical engineer!

We designed a focused, beginner-friendly course that helps you consolidate your Python basics in only 2 hours. It’s perfect for junior programmers and learners who need Python as a secondary skill. In this course, you will quickly reinforce core concepts and build your confidence with Python.