Tools to try
Uncompyle6 works, with some bugs, for Python 3.x, and works well for 2.7.
- Recommended option to start with as it’s aiming to unify earlier forks and focusing on automated unit testing. The uncompyle6 GitHub page has more details.
- Works best for earlier 3.x versions, not best choice for 3.7+
If that doesn’t work, try decompyle3, a fork of Uncompyle6 that works better for 3.7 and higher (according to author of Uncompyle6).
If you still have problems, check the uncompyle6
and decompyle3
READMEs which link to other tools that may work better for your code
Limitations
You get your code back including variable names and docstrings, but without the comments.
Some code may not successfully decompile, particularly with unusual control flow, or more recent Python 3.x versions. This is due to bugs in these decompilers as Python has changed its bytecode.
Improving these tools
Raise GitHub issues for these projects if needed – both run unit test suites on a range of Python versions.
Funding is apparently a limitation on supporting more recent Python versions (3.7 onwards) in uncompyle6
and decompyle3
– sending donations would help.
Preventing loss of code in future
See this answer for some tips that may work in your editor or IDE, including VS Code.