Python Bytecode

In the compilation stage, Python first translates source code to a specific Intermediate Representation (IR), and then this IR is converted to machine code. The IR that Python uses is called Python Bytecode. The Python Bytecode is stored as .pyc file.

When we are given a .pyc file, we should try using a Python Bytecode decompiler to get readable source code. For newer versions of Python, use decompyle3:

For older versions of Python, use uncompyle6:

There are some other similar tools for specific Python versions. If the decompiled output does not make sense, always try using other tools.

Last updated