How to recover a .py file from PyInstaller .exe?
Asked Answered
M

2

8

I lost my original python code that I've been working on for months, it's packed into an .exe using PyInstaller and that's all I have.

I tried this: Exe to python with pyinstaller?

I was able to extract a file that has some of my source code in it but it's filled with all this gibberish:

Graphing...

z Value="é z0" MÚ0c C s g | ]}|  d d¡qS )ú"Ú )Ú replace)Ú.0Ús© r úGraphLEDView_1.1.pyú ( s r c C s g | ]}t  d d|¡qS )z[^0-9]r )ÚreÚsub)r Ú LedDatar r r
r ) s )Údtype)é g @)Ú figsizei¸ é z Sensor {}g ü?)ÚlabelÚ linewidthÚLEDsÚ BrightnessÚlogz

What was extracted was a file with the name of my code without the .py extension and a folder of .pyc files none of which are my code, just the dependent libraries. Can someone help me get my code back? A lot of work down the drain if I can't get it back... I feel really dumb. Thanks

Magdaleno answered 21/3, 2019 at 22:6 Comment(6)
Looks like maybe another viable tool at github.com/countercept/python-exe-unpackerShiv
Thanks. I just tried it by going: python python_exe_unpack.py -i myprogram.exe, and I got an error, TypeError: extractFiles() takes 1 positional argument but 2 were givenMagdaleno
Unfortunately, I haven't personally used this program, you might try reaching out to the developer. Sorry I can't be of more help!Shiv
Do you use onefile or onedir for packaging? (It looks like onefile) can you provide the complete file for download?Stumpf
and provide your python version: for example, Python 3.7.7(python --version) and packages information (pip freeze)Stumpf
I put in a pull request to fix the error you have here: github.com/countercept/python-exe-unpacker/pull/16 - The version with the fix is forked here: github.com/johnashu/python-exe-unpackerPenetrant
J
0

It doesn't seem to be possible. Pyinstaller converts the .py file into binary which your computer can understand. From what I can see, there isn't a way to convert the .exe to a .py file again.

Jacquelynnjacquenetta answered 25/6, 2021 at 22:16 Comment(1)
What you say is incorrect. It is possible to convert .exe to .py. Here - Converting .exe to .pyToolis
T
0

Try using pyinstaller extractor: github link. It converts exe to py with the following command:

python pyinstxtractor.py <filename>

After you extract the pyc files, you can use a decompiler like python-uncompyle6 to get the py files. It is not guaranteed that you will get the original code, and there will be no comments, but it is the best option.

Tobacconist answered 20/2, 2024 at 4:12 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.