Convert PYO to PY
Recover readable Python source from legacy Python 2 optimized bytecode.
How to convert pyo to py file
- Programming
- No ratings yet.
Old Python 2 software may provide only a .pyo file when an editor, code-review system, or maintenance project requires readable .py source. The conversion requires decompilation because a PYO file does not contain the original source text.
What the PYO format is
A PYO file is optimized Python bytecode produced by Python 2 when code is run with -O or -OO. Python 2 commonly stored it beside the source as module.pyo; Python 3.5 and later removed the separate PYO format and store optimized bytecode as tagged .pyc files.
You may find PYO files in archived Python 2 applications, embedded-device software, and old installation directories containing files such as __init__.pyo. PYO is compiled bytecode for the Python interpreter, not a compressed or renamed copy of the original .py file.
What the PY format is
A PY file is plain-text Python source code that can be opened, edited, searched, versioned, and run with a compatible interpreter. It is the format expected by source editors, code repositories, linters, and most development tools.
Decompilation can recreate executable-looking Python code, but normally cannot restore comments, original whitespace, source encoding comments, exact formatting, or source constructs discarded during compilation. Many names remain in bytecode, but they are not guaranteed to match the author’s intended names.
How to convert PYO to PY
- Identify the bytecode version. A
.pyoextension usually indicates Python 2, but Python 2.5, 2.6, and 2.7 bytecode are different. Use the surrounding application, its documentation, or a bytecode-inspection tool to determine the version from the file header. The decompiler must support that version. - Preserve the original. Work on a copy and avoid executing an untrusted PYO file. If the file contains proprietary code, do not upload it to a third-party service without authorization.
- Install a local decompiler.
uncompyle6is a commonly used open-source option for Python bytecode; install it in an isolated environment withpython -m pip install uncompyle6.pycdc, built from its official repository, is another local option. Check each project’s supported bytecode versions before choosing it. - Run the decompiler. For example,
uncompyle6 -o recovered module.pyowrites recovered files underrecovered. Some releases or wrappers may reject the.pyosuffix even though the file contains standard Python 2 bytecode. In that case, copy it tomodule.pycand retry; renaming changes only the filename, not the bytecode. - Capture standard output when necessary. If the tool prints source instead of creating a file, use
uncompyle6 module.pyo > module.py. Inspect the result before replacing any existing source. - Validate with the matching interpreter. First check Python 2 output with a suitable Python 2 interpreter, such as
python2 recovered/module.py, in a controlled environment. Fix decompiler errors manually, then port the code to Python 3 with tools such as2to3where appropriate; automatic porting does not replace testing.
No ordinary rename, archive extractor, or text export operation converts PYO into source. Reputable online converters are generally not a practical recommendation for this format: support depends on the exact Python bytecode version, and uploading proprietary software exposes its code. A local decompiler is safer and usually more reliable.
Quality and compatibility limits
Decompilation is an approximation. Comments, formatting, source-only syntax, and some original organization are lost. Python 2 compilation with -O removes assertion statements; -OO also removes docstrings. The recovered file may therefore differ in behavior or documentation even when it runs.
Review indentation, exception handling, generators, decorators, string encodings, imports, and control flow. A decompiler can produce syntax errors or subtly incorrect code when it does not fully support the bytecode version or a particular compiler construct.
A PYO file may also depend on package modules, data files, native extensions, environment variables, and a specific working directory. Successful conversion produces source text, not a self-contained replacement application.
PYO vs PY: format comparison
How the PYO and PY formats compare on the properties that matter most for this conversion.
| Property | .PYO Python Optimized 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 | No | Yes |
| Best used for | Embedding in applications | Editing and post-production |
| Introduced | — | 1991 |
| Developer | Python Software Foundation | Python Software Foundation |
| MIME type | — | text/x-python |
The database currently does not contain any direct pyo file converter links.