Stack Overflow has many questions about
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With