Fundamentals 5 min read

uncompyle6: A Cross‑Version Python Bytecode Decompiler – Installation, Usage, and Examples

This article introduces uncompyle6, a native Python tool that decompiles bytecode from Python 1.0 through 3.8 (including Dropbox Python 2.5 and PyPy), and provides step‑by‑step installation commands, usage syntax, option details, and practical examples for batch decompilation.

Python Programming Learning Circle
Python Programming Learning Circle
Python Programming Learning Circle
uncompyle6: A Cross‑Version Python Bytecode Decompiler – Installation, Usage, and Examples

uncompyle6 is a native Python cross‑version decompiler that can translate compiled Python bytecode back into equivalent source code, supporting versions from Python 1.0 up to 3.8, as well as Dropbox Python 2.5 bytecode and some PyPy bytecode.

For implementation details, readers are encouraged to consult the official documentation.

Installation

<code># Direct installation
$ pip install uncompyle6

# Install the latest version from source
$ python setup.py install</code>

Basic Usage

<code># Decompile a compiled file (pyc or pyo)
$ uncompyle6 *compiled-python-file-pyc-or-pyo*</code>

Help and Options

<code>Usage:
  uncompyle6 [OPTIONS]... [ FILE | DIR]...
  uncompyle6 [--help | -h | --V | --version]

Examples:
  uncompyle6 foo.pyc bar.pyc               # decompile to stdout
  uncompyle6 -o . foo.pyc bar.pyc          # decompile to ./foo.pyc_dis and ./bar.pyc_dis
  uncompyle6 -o /tmp /usr/lib/python1.5    # decompile whole library

Options:
  -o <path>     output decompiled files to this path
  --compile | -c <python-file>   attempts a decompilation after compiling <python-file>
  -d            print timestamps
  -p <integer>  use <integer> number of processes
  -r            recurse directories looking for .pyc and .pyo files
  --fragments   use fragments deparser
  --verify      compare generated source with input byte‑code
  --verify-run  compile generated source, run it and check exit code
  --syntax-verify compile generated source
  --linemaps    generated line number correspondences between byte‑code and generated source output
  --encoding <encoding>   use <encoding> in generated source according to PEP‑0263
  --help        show this message

Debugging Options:
  --asm | -a            include byte‑code (disables --verify)
  --grammar | -g        show matching grammar
  --tree={before|after}
  -t {before|after}     include syntax before (or after) tree transformation (disables --verify)
  --tree++ | -T         add template rules to --tree=before when possible

Extensions of generated files:
  '.pyc_dis' '.pyo_dis'   successfully decompiled (and verified if --verify)
    + '_unverified'       decompiled but verification failed
    + '_failed'           decompilation failed (contact author for enhancement)</code>

Examples

<code># Use -o to specify output location
$ uncompyle6 -o test.py test.pyc</code>
<code># Batch decompilation script
import os
file_path = '/Users/escape/Paoding/trident/Trident-Backend/user_proxy'
for root, dirs, files in os.walk(file_path):
    for file in files:
        file_name, file_suffix = file.split('.')
        if file.endswith('pyc') or file.endswith('pyo'):
            print(f">>> filename: {filename} to do ...")
            os.system(f"uncompyle6 -o {os.path.join(root, file_name, 'py')} {filename}")</code>

For more details, refer to the original article linked at the end of the source.

bytecodedecompileruncompyle6
Python Programming Learning Circle
Written by

Python Programming Learning Circle

A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.