Python source code recovery from exe - python

I had a python program written which I converted to an exe binary using py2exe. I have all of the files generated in the dist folder but due to a system crash, I lost the source code.
Is there a way to get the .py source code file back from .exe or other supporting files generated by py2exe?

According to the following links, you can extract your .pyc files from library.zip and then use decompyle to obtain .py files similar to what you started with.
http://bytes.com/topic/python/answers/101743-py2exe-there-way-go-backwards-exe2py
http://sourceforge.net/projects/decompyle/
Hope it works, and I hope you use github or bitbucket next time.

Related

Making a .exe file from python script. .exe does not find my modules in different folder

I've seen this post about a similar problem but I dont understand the solution. And I am using python 3 the other person is using python2
Link to post: Making a standalone .exe file of a python script
I made a python exe that uses multiple files.
When all the files are in one directory the exe works.
Now i put some order in my directory.
E.G. making a source folder where my sources are
making a script folder where my scripts are
Using an IDE the scripts still run, so the relations aren't wrong.
my directories look like this:
"main
main.py
sources
sources.py
buttons.py
scripts
scripts.py"
I converted main.py to exe with pyinstaller
I made an error. Went to far up the tree to find the spoken of files.

How to encrypt and convert my python project to exe

I have created python desktop software. Now I want to market that as a product. But my problem is, anyone can decompile my exe file and they will get the actual code.
So is there any way to encrypt my code and convert it to exe before deployment. I have tried different ways.
But nothing is working. Is there any way to do that?.Thanks in advance
This link has most of the info you need.
But since links are discouraged here:
There is py2exe, which compiles your code into an .exe file, but afaik it's not difficult to reverse-engineer the code from the exe file.
You can of course make your code more difficult to understand. Rename your classes, functions to be non-sensical (e.g. rename print(s) to delete(s) or to a()) people will have a difficult time then.
You can also avoid all of that by using SaaS (Software as a Service), where you can host your code online on a server and get paid by people using it.
Or consider open-sourcing it :)
You can install pyinstaller per pip install pyinstaller (make sure to also add it to your environment variables) and then open shell in the folder where your file is (shift+right-click somewhere where no file is and "open PowerShell here") and the do "pyinstaller --onefile YOUR_FILE".
If there will be created a dist folder, take out the exe file and delete the build folder and the .spec I think it is.
And there you go with your standalone exe File.

Convert a visual studio python project to one executable file

I have finished my python project and now want to transfer the project into one file, so a user can just double click it and doesn't have to compile it first.
Therefore, I wanted to know if this is possible with python.
I 've read that you can convert a single python script into an executable file using pyinstaller. But in my case I have many files in different folders and I want them to be include in the executable file because otherwise the programm doesnt work.
I also tried this via the auto-pyto-exe converter (https://github.com/brentvollebregt/auto-py-to-exe) but I didnt got the results I wanted.
Therefore, my question is, how can I convert my visual studio python-project with many different files and folders into one executable file, so a user can just double click the file to start it?
Edit
In the other folder are also .py files like some FileImport.py or View.py. I separated these files that the whole project looks cleaner.
The Folder structure looks as follows:
-Views
---MainView
---UpdateView
---AnotherView
-Controllers
---MainViewController
---UpdateViewController
-Model
---MainModel
I found the solution. As it appears the pyinstaller can find all dependencies when you compile your script via pyinstaller myscript.py. PyInstaller creates three different folders where all necessary files are located. In the dist folder one executable is located which can be used from computers without python installed.
I hope this helps somebody who has the same problem.

How to share a python program as an executable?

I wrote a Python program with GUI built using tkinter. I want to share my project as an open-source software in Git. My goal was to enable the end-user to download/clone my repository and run an executable present in it.
So I made my Python file to an executable using pyinstaller. I then pushed all the files created by the pyinstaller (ex: dist, build files) to my repository. Is this the correct way to distribute a software?
Though I wrote my software only using Python, the files created by pyinstaller dominated the result:
Furthermore, when I tried cloning my repository the executable present in it throws an error, though the executable I created originally works without any problem.
I used the flag --onefile to create the executable using pyinstaller. Someone please help me out.
It might be getting blocked, I would recommend creating a release in Github and archive the executable so others can download it from there or you can just archive the executable. Not sure if Github blocks plain executables or not but is safer to just archive it into a .zip or a .rar, or .tar file.

Python: How to offer a single executable file without showing the code in 2020

Stack Overflow has many questions about
How to give someone else a python script protecting the source code
How to compile python files
How to create packages and deploy the code
But I could not find the answer to my problem:
I want to give someone else my python script, without giving him the source code. My current attempt is compiling the file and giving away the .pyc file.
This is for sure not the best solution. Moreover, my code is made by different files. To offer a single executable pyc file, I put the code all together in a single file before compiling it: a true hell for a developer
How can I obtain my goal in a cleaner way?
Side-notes
I know .pyc files are not going to hide so much, but it is for sure better compared to giving .py files
Still, .pyc files can be incredibly problematic (as they can be system-dependant)
You can create a .exe file using pyinstaller.
pip install pyinstaller
then, open terminal in your source code directory and use the command:
pyinstaller --onefile source.py
If you have database connection with python file then it can be added using:
pyinstaller --onefile --add-data 'database.db:.' source.py
Here, :. shows database.db is a source data file and it will copy on the top level of your python application.
using "pyinstaller sroucecode.py --onefile" command will generate an executable file on Windows. This can be a way should it be desired to ship the functionality but hide the code.
There is tool, which might help you to achieve described outcome, but only if destination machine is able to run .exe files.

Categories

Resources