Convert pyc to py

Convert PYC to PY

Recover readable Python source from bytecode with version-matched decompilers.

Make PY files online

We can't read PYC files yet, so this conversion isn't available. If you can export your work to one of these formats, we'll turn it into PY:

Want to convert PYC to PY?

Let us know. We pick the conversions to add next by how many people ask for them.

How to convert pyc to py file

People need a PY file when a program, developer, or archive contains only a compiled Python module but its source must be inspected or edited. This is decompilation rather than a lossless format conversion, so the recovered code may not match the original.

What the PYC format is

PYC files contain Python bytecode and a serialized code object for execution by a Python interpreter. Python commonly creates them when importing or compiling a PY file, placing them in __pycache__ with names such as module.cpython-311.pyc. Installed packages, application deployments, and bundled software may contain PYC files without the corresponding source.

A PYC file has a header containing interpreter and cache metadata, followed by marshaled bytecode data. It normally does not preserve comments, original whitespace, quoting, formatting, or the exact arrangement of the source. Many identifiers remain in the code object, but optimization, obfuscation, generated code, and compilation details can remove or alter information.

What the PY format is

PY is a plain-text Python source file intended for reading and editing. Python interpreters, IDEs, linters, formatters, version-control systems, and packaging tools work directly with PY files. Unlike reconstructed output, an original PY file retains the developer's comments, formatting, source organization, and usually all source-level intent.

Renaming a PYC file to .py does not convert it: the result is still binary bytecode and is not valid Python source.

How to decompile a PYC file

  1. Make a copy of the PYC file and work on that copy. Do not execute an untrusted PYC or reconstructed script; decompilers and Python imports should be run in an isolated environment when the file is untrusted.
  2. Identify the Python version that created the file. A name such as module.cpython-311.pyc identifies CPython 3.11, but a standalone filename may not contain this information. The producing package, PYC header, or bytecode magic number can provide additional clues.
  3. Install a decompiler whose documented support includes that bytecode version. For example:
python -m pip install decompyle3
decompyle3 -o recovered path/to/module.pyc

The output directory should contain reconstructed source files. If the installed command is unavailable on the system path, run the executable from the environment's script directory.

For a different supported version, try uncompyle6:

python -m pip install uncompyle6
uncompyle6 -o recovered path/to/module.pyc

decompyle3 and uncompyle6 support specific ranges of Python bytecode rather than every current release, so check each project's compatibility documentation before choosing between them. pycdc is another local option when its release supports the file's bytecode version:

pycdc path/to/module.pyc > recovered.py

Online services such as PyLingual can be useful for non-confidential files when their published support includes the PYC's Python version. Uploading bytecode sends potentially proprietary code to a third party and may subject it to size, retention, or processing limits; use a local tool for confidential software and verify the downloaded output before opening or running it.

Check and repair the recovered source

Open the generated .py file in an editor and inspect syntax, imports, exception handling, generators, comprehensions, decorators, closures, and dynamically generated code. Compile it with the intended interpreter:

python -m py_compile recovered.py

Successful compilation checks syntax only. Run relevant tests and compare behavior with the original application before using the result as replacement source. A decompiler may emit valid-looking code with incorrect control flow or missing details.

Compatibility and recovery limits

Bytecode is tightly coupled to Python implementations and releases. A PYC created by Python 3.11 or 3.12 may not work with a decompiler that supports only older bytecode; Python 2 PYC files generally require Python 2-compatible tooling. A damaged, truncated, optimized, obfuscated, or modified file may produce incomplete output or fail entirely.

Decompilation cannot restore comments, original formatting, unavailable external modules, package data, or source files referenced by the code. Native extension modules are not Python PYC files and require different recovery methods. The original PY file, version-control repository, deployment archive, backup, or package source is the only reliable way to obtain the exact source.

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

Frequently asked questions

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

A .pyc file can sometimes be decompiled into approximate .py source, but it cannot usually be restored exactly. The original comments, formatting, and some source-level details are normally lost during compilation.

Will the recovered .py code be identical to the original?

No, recovered .py code is usually a reconstruction of the compiled bytecode rather than the original source. Names and program structure may be partly preserved, but comments, spacing, some expressions, and other source details may be different or missing.

Why does .pyc to .py conversion fail for some Python files?

It often fails when the bytecode version does not match the decompiler or when the file was optimized, obfuscated, damaged, or produced by a different Python implementation. A .pyc file also may contain only a module's compiled code, so it cannot restore source files or project structure that were never included.

Can I run the resulting .py file exactly like the original?

Often, but not always; the recovered code may need manual corrections before it runs. Python-version-specific bytecode, missing external files, and lost source-level details can cause syntax errors or changed behavior.

Reverse conversion

Convert to py from
other formats

Share on social media: