Is it possible to decompile a compiled .pyc file into a .py file?

Howard  picture Howard · Mar 13, 2011 · Viewed 294.6k times · Source

Is it possible to get some information out of the .pyc file that is generated from a .py file?

Answer

RichVel picture RichVel · Feb 11, 2013

Uncompyle6 works for Python 3.x and 2.7 - recommended option as it's most recent tool, aiming to unify earlier forks and focusing on automated unit testing. The GitHub page has more details.

  • if you use Python 3.7+, you could also try decompile3, a fork of Uncompyle6 focusing on 3.7 and higher.
  • do raise GitHub issues on these projects if needed - both run unit test suites on a range of Python versions

With these tools, you get your code back including variable names and docstrings, but without the comments.

The older Uncompyle2 supports Python 2.7 only. This worked well for me some time ago to decompile the .pyc bytecode into .py, whereas unpyclib crashed with an exception.