Install & Compatibility
Where this runs
tested against v3.9.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 23.3MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.6s · import 0.000s · 24MB
22MB installed
● package 22MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
decompile_file
✓ from uncompyle6 import decompile_file
✗ from uncompyle6.decompile import decompile_file
This quickstart demonstrates how to programmatically decompile a `.pyc` file using `uncompyle6.decompile.decompile_file`. It first creates a dummy Python source file, compiles it into bytecode, and then uses `decompile_file` to print the reconstructed source code to standard output. Remember to install `uncompyle6` and its dependencies first.
import os
import py_compile
import sys
import textwrap
from pathlib import Path
from uncompyle6.decompile import decompile_file
# 1. Prepare: Create a dummy Python file and compile it to .pyc
temp_dir = Path("uncompyle6_quickstart_temp")
temp_dir.mkdir(exist_ok=True)
source_path = temp_dir / "my_module.py"
source_path.write_text(textwrap.dedent("""
def hello_world():
\"\"\"A simple greeting function.\"\"\"
print("Hello from uncompyle6!")
class MyUtil:
def __init__(self, name):
self.name = name
def greet(self):
return f"Greetings, {self.name}!"
"""))
# Compile the .py file to .pyc (ensures a standard .pyc structure)
py_compile.compile(str(source_path), cfile=str(source_path.with_suffix('.pyc')))
pyc_path = source_path.with_suffix('.pyc')
# 2. Decompile the .pyc file programmatically
try:
print(f"--- Decompiling {pyc_path.name} ---")
# decompile_file takes the input .pyc path and an output file-like object
decompile_file(pyc_path, sys.stdout)
print(f"--- Decompilation complete ---")
except Exception as e:
print(f"An error occurred during decompilation: {e}")
finally:
# 3. Cleanup temporary files and directory
if temp_dir.exists():
import shutil
shutil.rmtree(temp_dir)
uncompyle6 --version
Debug
Known issues
gotchauncompyle6 can run on modern Python versions (e.g., 3.6-3.12), but it primarily supports decompiling bytecode up to Python 3.8. Attempting to decompile `.pyc` files from newer Python versions will likely result in errors or incorrect output.fixVerify the Python version that compiled the `.pyc` file. For bytecode from Python 3.9+, you might need to use other tools or wait for future uncompyle6 updates supporting those versions.
affects: All versions of uncompyle6 when used with Python 3.9+ bytecode.
breakingThe `xdis` library, a core dependency, frequently undergoes API changes. These changes can break `uncompyle6` if its bundled or required `xdis` version becomes incompatible with a newly installed or updated `xdis`.fixAlways install `uncompyle6` using `pip install uncompyle6` to ensure compatible `xdis` versions are pulled in. If issues arise, try `pip install uncompyle6 --upgrade` to get the latest compatible versions of both libraries.
affects: Versions 3.7.0, 3.9.1, 3.9.2, 3.9.3 (and potentially others) due to explicit mentions in release notes.
gotchaWhen Python code is compiled with optimization flags (`python -O` or `python -OO`), certain elements like docstrings and `assert` statements are removed from the bytecode. Decompiling such `.pyc` files will result in missing these elements.fixIf you need to recover docstrings or assert statements, ensure the original `.pyc` file was compiled without Python's optimization flags (`-O` or `-OO`).
affects: All versions, as this is a characteristic of Python's bytecode optimization.
Upgrade
Version history
3.9.3latest on PyPI · released Sep 29, 2025
Audit
Dependencies
xdisrequiredCore dependency for bytecode disassembly and parsing. Frequent API changes in xdis can necessitate uncompyle6 updates.