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.
Related
I tried to create an executable file in Windows from a kivy project with PyInstaller, and even though it appears to have been successfully created, when I try to run it, I get this
What could cause this? I'm relatively new to kivy, and any help will be much appreciated
well, I actually figured it out myself. Though I don't think that my solution is in any way elegant and it might cause some other problems in the future, but i just edited the pyi_rth_pkgutil.py from PyInstaller package directory (how it is now, how it used to be) and reran the pyinstaller package creation script. It just worked after that
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
I am trying to create a standalone exe from python code using nuitka. Its a rather sizable program with several libraries including for instance PyQt5.
I have created the exe using:python -m nuitka --standalone --follow-imports --enable-plugin=qt-plugins --enable-plugin=numpy --python-flag=no_site --mingw64 rs_main.py
I have also tried without the --mingw64 and --python-flag=no_site flags but they all give me the same error when I try to execute the resulting exe:
ImportError: LoadLibraryEx 'D:\... ...\rs_main.dist\PyQt5\QtWidgets.pyd' failed: The specified procedure could not be found.
I checked and the file does exist in the correct location.
The compiling itself gives me some warnings but no errors.
Online I found my problem here: https://github.com/Nuitka/Nuitka/issues/73 but to be honest I do not fully understand their journey towards the solution and as I think I understand it should be solved in my version of nuitka which is 0.6.6. On top of that I am running python 3.7.3 on a windows 10 machine.
Hopefully someone can explain me the solution in the referenced link or offer one of their own. thanks in advance.
So this is not really an answer to my question, but if anyone comes across this question, maybe my solution is good enough for them as well.
So although I know it does not do the same as Nuitka I was finally able to create a standalone exe using pyinstaller including some flags such as --hidden-imports and add the path to Qt but I found the feedback of pyinstaller to be rather understandable.
So maybe if you have the same problem as me, this might be a different approach for you as well.
I have a python project that has the following structure:
I am using the following for compilation, python -m nuitka --follow-imports --standalone C:\Users\probat\Documents\main.py
The project is being compiled as a standalone executeable so I also need to include Sub-Directory and also its contents (rules.txt and settings.ini) - these are not being included currently. I know I am obviously in fault here but after reading the user documentation and searching everywhere I failed to find a solution. I tried using --include-plugin-directory but that didn't work. I may not be using it correctly or I am wrong for using it. Any help is appreciated.
FWIW I just copy the folder and its contents after the compilation is done. This is part of the workflow. I did the same with PyInstaller, so it does not seem awful to me.
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.