Install the necessary tools:
Converting an executable ( ) file back into Python source code ( ) is a process known as decompilation
You need a tool called pyinstxtractor .
First, you'll need a Python installation on your machine. For best results, try to use the that was used to create the original executable, especially when using older extraction tools. Newer tools like pyinstxtractor-ng have largely eliminated this requirement, but version compatibility can still affect decompilation quality.
Modern versions of pyinstextractor automatically fix the headers for you. You can skip straight to Step 3.
The most effective, modern tools for this are and uncompyle6 . Option A: Using Decompyle++ (Recommended for Python 3.9+)
is a compiled binary, you cannot simply rename the file. You must extract the original bytecode and then decompile it: Extract the Archive
: If the developer used a tool like PyArmor to obfuscate the code, the decompiled output will likely be unreadable or may fail to decompile entirely.
Bundle those .pyc files with the Python DLL (the engine that runs the code).
When PyInstaller builds an executable, it packages several layers together:
: Converting the extracted Python bytecode ( .pyc files) back into human-readable source code ( .py ). Recommended Tools
uncompyle6 your_program.exe_extracted/your_program.pyc > recovered.py
Contains the Python interpreter, standard libraries, third-party packages, and crucially, the PYZ archive (which holds the compiled .pyc files of your actual script).
These files are critical because they contain the structural headers needed to fix your main bytecode file if it was extracted without them. Phase 2: Decompiling .pyc Files to .py Source Code
You generally need to use a decompiler that matches the Python version used to create the .exe .
I have included a crucial "Reality Check" section at the top, as converting an executable back to source code is rarely a perfect 1:1 process. This post focuses on reverse engineering techniques for your own lost code or for educational analysis.
Install the necessary tools:
Converting an executable ( ) file back into Python source code ( ) is a process known as decompilation
You need a tool called pyinstxtractor .
First, you'll need a Python installation on your machine. For best results, try to use the that was used to create the original executable, especially when using older extraction tools. Newer tools like pyinstxtractor-ng have largely eliminated this requirement, but version compatibility can still affect decompilation quality.
Modern versions of pyinstextractor automatically fix the headers for you. You can skip straight to Step 3.
The most effective, modern tools for this are and uncompyle6 . Option A: Using Decompyle++ (Recommended for Python 3.9+)
is a compiled binary, you cannot simply rename the file. You must extract the original bytecode and then decompile it: Extract the Archive
: If the developer used a tool like PyArmor to obfuscate the code, the decompiled output will likely be unreadable or may fail to decompile entirely.
Bundle those .pyc files with the Python DLL (the engine that runs the code).
When PyInstaller builds an executable, it packages several layers together:
: Converting the extracted Python bytecode ( .pyc files) back into human-readable source code ( .py ). Recommended Tools
uncompyle6 your_program.exe_extracted/your_program.pyc > recovered.py
Contains the Python interpreter, standard libraries, third-party packages, and crucially, the PYZ archive (which holds the compiled .pyc files of your actual script).
These files are critical because they contain the structural headers needed to fix your main bytecode file if it was extracted without them. Phase 2: Decompiling .pyc Files to .py Source Code
You generally need to use a decompiler that matches the Python version used to create the .exe .
I have included a crucial "Reality Check" section at the top, as converting an executable back to source code is rarely a perfect 1:1 process. This post focuses on reverse engineering techniques for your own lost code or for educational analysis.