Following the feedback we get for our py2exe decompiler (a decompiler for Windows executables created by py2exe1), we noticed that there is a community need for this tool. Most of the feedback comments are requests for help related to missing dependencies and similar problems.
However, a couple of months ago, there had been an API-breaking release for the decompiler module we use (uncompyle6), and our previous tool no longer worked with this new version.
We adapted our Python decompiler program to work with the new API and to mitigate future problems like this, we decided to compile our Python decompiler into a self-contained Windows executable. This way, one can use our decompiler on Windows without Python or any dependencies. You can find the updated source code an its binary on GitHub here.
In the remaining part of this blog post, we describe the compilation process and an issue we encountered. As compiler, we picked PyInstaller because we are already familiar with it. To compile into a single-file Windows executable, we initially used the following command:
pyinstaller.exe -F decompile-py2exe.py
(Without the -F flag, the process would generate a folder with executable, dependencies, and support files, which makes it less self-contained.)
We encountered an error when we tested this executable (always test your compiled programs):
Traceback (most recent call last): File "site-packages\uncompyle6\scanner.py", line 511, in get_scanner File "importlib\__init__.py", line 126, in import_module File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 953, in _find_and_load_unlocked ModuleNotFoundError: No module named 'uncompyle6.scanners.scanner33'
This happens when PyInstaller is not able to identify all required modules. The module we are missing is uncompyle6.scanners.scanner33, and this can be solved by recompiling the executable and directing PyInstaller to include this module explicitly using option –hidden-import, like this:
pyinstaller.exe -F --hidden-import=uncompyle6.scanners.scanner33 decompile-py2ex
To summarize: to compile our decompiler, you need Python 3 and install modules uncompyle6 and pefile, for example via pip, and run the command above.
Remark that decompile-py2exe is a py2exe decompiler, hence it cannot be used to decompile itself (being compiled with PyInstaller) but there are other tools that can.
If you still have errors (or don’t want to install Python), use the binary we provide on github, but do let us know about the issues you encounter.
1: a tool to compile Python programs into Windows executables
One thought on “Compiling Our Python Decompiler”