Convert pyc to py

Convert PYC to PY

Explains why .pyc files are hard to restore and which tools may help

How to convert pyc to py file

What .pyc and .py files are

.py files are Python source files that you read, edit, and run. .pyc files are compiled Python bytecode files that Python can execute faster after the source has been compiled.

Can a .pyc file be converted back to .py?

Not perfectly. A .pyc file does not contain the full original source code. In many cases, it can be decompiled into similar Python code, but the result may differ from the original and may not be fully readable or runnable without fixes.

What is lost in .pyc files

When Python compiles source code, it keeps bytecode and some metadata, but it does not preserve comments, original formatting, and often not all variable names or structural details exactly as written in the source.

When decompilation may work

Decompilers can sometimes recover code from .pyc files created by supported Python versions. Success depends on the Python version, the integrity of the file, and whether the bytecode has been obfuscated or altered.

Tools you can try

For inspection or recovery, tools such as uncompyle6 and decompyle3 are commonly used. Use the tool that supports the Python version that created the .pyc file. Newer bytecode versions may not be supported by older decompilers.

Example command

To try decompiling a file with a supported tool, run:

uncompyle6 example.pyc > example.py

Afterward, review the output carefully and test it, because decompiled code may need manual correction.

Important limitations

.pyc files are not a reliable backup of source code. They are intended for execution, not for source recovery. If the file was generated by a different Python version, is damaged, or was protected/obfuscated, decompilation may fail or produce incorrect results.

Best way to recover source

If you need the original code, look for the .py file in version control, backups, deployment archives, or from the original developer. If no source exists, decompilation is only a last-resort recovery method.

PYC vs PY: format comparison

How the PYC and PY formats compare on the properties that matter most for this conversion.

Comparison of the PYC and PY file formats
Property .PYC Python compiled bytecode .PY Python source file
Plain-text readable No Yes
Text formatting None Basic
Images No No
Further editing Not directly editable Easy
Opens in a web browser No No
Typical file size Very small Small
Open standard Yes Yes
Best used for Embedding in applications Editing and post-production
Introduced 1991 1991
Developer Python Software Foundation Python Software Foundation
MIME type text/x-python

Reverse conversion

Convert to py from
other formats

Share on social media: