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.
Related
I Created a Program That Has 2 .py files.
I Want To Make The Program a .exe file, I do it using cx_Freeze.
My Problem Is That I Convert The main.py To .exe but The Second Python File Is Still a .py File.
I Don't Want It Be a .py Because If It Is The User Can See The Code.
If I Also Convert The Second Python File The Program Doesn't Work Because I import The Python File In The Main File.
Any Suggestions?
(I Don't Want To Copy The Second Python File To The Main Python File)
You are chasing the wrong rabbit here. The various tools that generate executable files from Python code are not compilers. They are just tools that embed a Python interpretor with py (or pyc) files to allow users to use the program without a prior Python installation.
Said differently you should not use them to hide your code (except from people not knowing a lot of Python): a pyc does not contain text code but according to the answers to Is it possible to decompile a compiled .pyc file into a .py file? , tools exists that convert back a pyc file into a py file (of course except the comments).
IMHO, you should better google for python obfuscate to find tools dedicated to obfuscation, what neither cx-freeze nor pyinstaller are.
BTW while there are appropriate use cases for obfuscation you should be aware that a determinate attacker can always circumvent it. The reason why the real protection for intellectual property is law and not technics...
I'm not sure how two or more .py files can be converted to .exe.
But in python the easiest way to convert to .exe is a module named pyinstaller .
You can install it using command pip install pyinstaller can get it . After just go to the directory where your project files are and open command prompt in that directory and execute pyinstaller file_name
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.
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.
I have many python modules for my project. And I need to put those all on the server so that they will automatically run every week.
so now I am thinking about how I can move all those modules to the server. Should I package it up or should I make them into the exe file to be installed?. I do not make the GUI so I think might exe is not a good choice. but I am open to all suggestion because now I do not know exactly what I should do.
I used Pyinstaller to create a standalone exe file for a PyQt project. I did not use the single file option because the exe that is created with the single file option takes too long to open. Therefore, Pyinstaller created a dist folder that contains a bunch of files including my program.exe file. I would now like to create a setup.exe file that will place the contents of my dist folder in the program directory and create a shortcut in the start menu and on the desktop. I want it to be super simple for the user. Maybe like the setup.exe files that you get when you download a program from CNET. I found Inno-setup, which looks promising. However, I do not know if there any special considerations because the program is a standalone program create from a python/PyQt program. Thanks! Anyone have experience with this task? Is there a program everyone is using for this task that I do not know about?
Inno-Setup or NSIS are probably the easiest to use. You just tell them what files to include and where to put them and then they will create a nice installer for you. I wrote a short tutorial on my experiences using InnoSetup that you might find helpful:
http://www.blog.pythonlibrary.org/2008/08/27/packaging-wxpymail-for-distribution/
Note that this tutorial was based around a wxPython app I wrote, but the concepts are the same.