PY PYC
File conversion

Convert PY to PYC

QUICK ANSWER
Is it possible to convert PY to PYC?
Yes - PY converts to PYC.

Python places the compiled .pyc file in the __pycache__ subfolder named with the interpreter version tag, for example yourscript.cpython-312.pyc. Python also compiles modules automatically on import, so the manual command is mainly useful for pre-compiling or catching syntax errors before deployment.

Also to PYC: PYO

On this page

Tested on macOS, Windows & Linux
Last verified Oct 2026

More free converters

HEIC, PNG, WEBP, MP3 and more - every tool here is free.

Open the toolbox

Why convert PY to PYC?

Pre-compiling to .pyc lets Python skip the parse step on the next run, giving a minor startup speed improvement. It also provides mild obfuscation since the bytecode is not human-readable source, though it can be decompiled with tools like uncompyle6.

How to convert PY to PYC

Python (py_compile) FREE

Run python -m py_compile yourscript.py in a terminal; the .pyc file appears in the __pycache__ subfolder alongside your script, named with the Python version tag.

Python (compileall) FREE

Run python -m compileall /path/to/project to compile every .py file in a directory tree at once; all .pyc files appear in their respective __pycache__ subfolders.

About these formats

Quality & what to watch

  • A .pyc file is tied to the exact Python version that compiled it - a file compiled with Python 3.12 will not load in Python 3.11 or earlier, because each version embeds a unique magic number in the header.
  • .pyc is not real source protection - tools such as uncompyle6 can decompile bytecode back to readable Python source; do not rely on it to protect intellectual property.
  • Python 3 always writes .pyc files into a __pycache__ subfolder, never next to the source file; the old .pyo optimized bytecode extension was removed in Python 3.5.

Frequently asked questions

Do I need to manually compile to PYC, or does Python do it automatically?
Python compiles any imported module to .pyc automatically the first time it runs. The manual py_compile command is useful for pre-compiling without running or for catching syntax errors early.
Can I distribute only the PYC files without the original PY source?
It is possible but fragile - .pyc files are version-specific and can be decompiled. Standard practice is to distribute the .py source instead.
Where does Python put the PYC file?
In a __pycache__ subfolder next to the .py source, with a name like yourscript.cpython-312.pyc reflecting the Python version that compiled it.