Why convert PYC to PYO?
.pyo was Python's optimized bytecode, nearly identical to .pyc but with assert statements removed and optionally docstrings stripped. Python 3.5 folded the optimization level into the .pyc filename, making .pyo redundant and removing it entirely. No Python version since 3.5 reads or writes .pyo files, so a PYC-to-PYO converter has no legitimate purpose.
About these formats
A .pyc file is compiled Python bytecode that CPython caches automatically to speed up startup. You do not normally need to open or touch it. To run one, use the matching Python version. To…
Open .PYC details →A .pyo file is a legacy Python optimized bytecode cache generated by running Python with the -O or -OO flag. The binary format is identical to a .pyc file. Python 3.5 eliminated the .pyo…
Open .PYO details →Quality & what to watch
- To produce optimized bytecode in Python 3.5+, run
python -O -m compileall yourscript.py; the result is a.pycfile named withopt-1in the__pycache__folder. - If you have a
.pyofile from a Python 2 or early Python 3 project, you can rename it to.pycand run it with the matching Python version - the interpreter will load it if the magic number matches. pyoand.pycwere functionally near-identical even before removal, which is exactly why the separate extension was eliminated in Python 3.5.
Frequently asked questions
Is .pyo the same as .pyc?
assert statements, which is why the separate extension was removed in Python 3.5.I have a .pyo file from an old project. Can I still use it?
.pyc; Python 3.5 and later do not create .pyo files but can still execute them.