I know a way to do this is using pyinstaller, however, after some research, I found out that a pyinstaller exe can be reverse engineered to get the original python script.
Do you know a way to compile a python script into an executable which can be shared with anyone ,even if they don't have the dependencies I used, or python, installed, and can not be reverse engineered?
I found two other threads talking about this, maybe you would like them:
How to make an encrypted executable file
https://www.quora.com/How-can-I-protect-my-Python-code-but-still-make-it-available-to-run
Related
Recently I have written a simple software in python and now I would like to share it with some people, but the problem is that they don't use python on their computer. Because of that an executable program could help me a lot and I tried to do it by using the package Pyinstaller with the following syntax:
pyinstaller --onefile -w program.py
After doing that three new folders was created and I found the executable file inside the dist folder but it doesn't work. When I clicked twice a error message showed up
Error message
Could anyone please tell why it happens and how I can work around this situation ? And also if you have another idea about how to convert .py to .exe besides using the Pyinstaller it would help me so much as well. I'm using python 3.8
Thanks
What error does it give you?
I haven't used Pyinstaller, but I've had success with auto-pye-to-exe as an alternative.
PyInstaller does not compile Python code into binary code. It just bundles your code into one installable exe file. So it does not improve the performance or code privacy.
Better option is to use CXFreeze or Nuitka. I personally prefer to use Nuitka because it worked in most cases where CXFreeze could not deal with.
Simply install Nuitka using pip or conda command. The documentation itself is quite good to start with.
I am doing this practice project to implement a LISP interpreter in Python, using help from here. I wanted to create an exe file for the project, executing which would start a REPL.
I tried using py2exe and pyInstaller but an error is thrown when I execute the output binary, saying that this script cannot run.
Where did I go wrong with my approach and what alternative ways can I use?
Thank you.
It is hard to know for sure but have you checked that all of the required dependencies for your project are either in the same folder as the created executable or (at least) in your path?
The other alternative that I am aware of (and use) is cx_Freeze. This particular exe builder has cross platform support.
cx_Freeze will attempt to automatically find all dependent python modules and include them in the final build. I imagine that the other two options work in the same manner. Packages that cannot be automatically located and binary dependencies (eg dlls, sos) must be explicitly specified in the build configuration scripts.
One method I have for debugging for missing dependencies is to manually copy the suspected missing dependency into the same folder as the .exe to see if it fixes the issue. If it does then I will specify it in the build configuration script.
See https://cx-freeze.readthedocs.io/en/latest/distutils.html for cx_Freeze documentation, in particular section titled build_exe.
Here is a good example of a non-trival setup.py for cx_Freeze: http://www.pythonexample.com/code/cx_freeze-setup/
I created a Python script for a Freelance job and I can't find how to compile/build/package it for easy sharing. The person for which I created it is not a technical one, so I can't explain him how to activate a virtualenv, install requirements and so on.
What is the easiest way for him to run the project right after downloading it?
Can the whole virtualenv be compiled into an .exe? If yes, can this be done inside a macOS system?
Yes you can package your python programs and it's dependencies with
Cx_Freeze
There are other python modules that do the same, personally i prefer cx_Freeze because it's cross platform and was the only one that worked out of the box for me.
By default cx_Freeze automatically discovers modules and adds them to the exe to be generated. but sometimes this doesn't work and you might have to add them by yourself
To create a simple executable from a file. you can just use the bundled cxfreeze script
cxfreeze hello.py --target-dir dist
but more for more complex applications that have different files you'll have to create a distutils setup script.
Note that cx_freeze doesn't compile your code like a traditional compiler. it simply zips your python files and all it's dependencies ( as byte code) together, and includes the python interpreter to make your program run. So your code can be disassembled. (if anyone wants to) and you'll also notice that the size of your program would be larger than it was initially (Because of the extra files included)
I ended up using PyInstaller as this worked out of the box for me.
I really like the PY2EXE module, it really helps me share scripts with other co-workers that are super easy for them to use.
My question is: when the PY2EXE module compiles the code into an executable, does the resulting executable process faster?
Thanks for any replies!
py2exe just bundles the Python interpreter and all the needed libraries into the executable and a few library files. When you run the executable, it uses the bundled interpreter to run your script.
Since it doesn't actually generate native code, the speed of execution should be about the same, possibly slower because of the overhead of everything being packaged up.
Partly, it bundles the python environment with the 'precompiled' pyc files. These are already
parsed into python byte code but they aren't native speed executables
I have been given a project to do. One of the main essential requirements is that this is given to the customer to run as single exe. It does not matter which programming language, however it will be comparing files between a set of default files and the customer’s files.
Is there any way I can do this so that I have one exe?
The py2exe library allows you to create exe files from your python code. I've not used it but it may do the job!
http://www.py2exe.org/
Alternatively, you can try pyinstaller.
See also: py2exe - generate single executable file
You're in luck! You can do just that with Python using the py2exe conversion utility.
You can find it at: http://www.py2exe.org/