How to make python pyinstaller executable sharable - python

I have tried a lot but I cant wrap my head around it. I make a lot of tkinter GUIs that I would like to share with others, but I am not able to. I use pyinstaller to create an executable out of it and mailing the compressed folder. It still doesn't seem to work as warnings are raised.
Some of the warnings include things like 'this folder has an executable file that might not be safe.'
The executable GUI works completely fine on my computer.
pyinstaller --onefile -n GUI -i icon.ico -w main.py
How am I supposed to make an executable that is sharable?

Related

How to create a onefile executable from a python script?

I have a decently complicated .py script, which uses several packages, incl matplotlib, numpy, and one custom, that is compiled from a fortran code. I want to make a windows executable out of this, that is distributeable in a way, that users don't need to have python installed on their computers for it to work.
When I make my .exe with pyinstaller --onefile myprogram.py the resulting .exe doesn't run on its own (if I doubleclick on it, the GUI it contains doesn't open), however, if I have anaconda installed, from anaconda prompt I can run it with .\path\to\program\myprogram.exe and it works all nicely (without creating an environment with matplotlib etc)
My question is: how can I make it so that the one file includes all the dependencies and I can just doubleclick on it and go?
Thanks in advance!

Python/C API project - compile to exe

I'm working on project where I am using Python/C API and C++. C++ is used for most part of application, mainly for gui (wxWidgets), while Python is used for calculations on large data sets, e.g. from files. I'm doing it in Visual Studio and when I run the project in IDE everything works fine, like I want it to. Also, the exe file that is created during the launch of the project in the visual studio, when it is in the same folder with the python .py file, also works as it should be. But what I want to achieve is a complete application contained in one exe.
While searching for a solution, I found various possibilities to create an exe from a python file. For example, PyInstaller which I tested for a simple "hello world" python file and it works. However, I don't know and can't find a solution how to combine the exe created in visual with a python file.
In PyInstaller github issues I found that line:
pyinstaller App.py --add-data 'pathtoexe\your.exe;.' --add-binary "pathtodll\your.dll;." --onefile --noconsole --clean
And I typed this into the console:
pyinstaller myPythonFile.py --add-data 'myVisualGeneratedFile.exe;.' --onefile --noconsole --clean
But after that, when I clicked generated exe file, nothing happens.
I hope that someone has done a similar thing before and I can find help here because I'm already losing my mind on it.
According to https://pyinstaller.readthedocs.io/en/stable/usage.html, you should use --add-binary and not --add-data.

Python- Compiling a .py program with .exe dependencies

I have written a Python (v3.8.1) Python program which relies on a c compiled .exe program. The Python script itself works as expected and I am ready to package it for use within Windows, in environments where Python is not installed.
I want to wrap both programs together under one .exe if possible and practical.
Based on a comment, I have gone through the compiling process with Pyinstaller using the following commands:
pyinstaller myprogram.py --hidden-import notional_library --add-data
compiled_c_program.exe;. --add-data dependency.COF;. -w -D
And the program works perfectly. However, when I change -D to -F to create a onefile.exe, the program breaks along the lines of the compiled c program, which is confirmed when I debug the program.
I have also tried adding the c program as a binary, but that does not work either.
Placing the dependencies in the same folder does work, and is an amenable solution, but I would still prefer to wrap both programs into a single executable if possible.

Pyinstaller: OSError: Cannot load AutoItX from path

So I have a program and whenever I start it from the command line it works totally fine. What I need now is an Executable and therefor I tried to do it with pyinstaller, which analyzes normally automatically which modules have been imported and it works fine with all of the modules except for autoit. The way I import it looks like that:
import autoit
So I tried to make an executable by following command:
pyinstaller --onefile ./rocketupload.py
Which gave me this Error (Excuse me, that I have to make a screenshot, but the window was open for a second and closed immediately afterwards, so I was not able to copy and paste it here):
I was able to create a functioning exe by copying the autoit dll to the path mentioned in the Error, but that is just a temporary solution, since I want the executable to be running not only on my PC.
I've also tried this one without succes:
pyinstaller --hidden-import=autoit --onefile --paths c:\users\semjo\appdata\local\programs\python\python37\lib\site-packages\autoit\lib .\rocketupload.py
So the problem here is that the autoit module does not get copied from pyinstaller so It cannot run the executable as inteded. But I dont know how to solve it, so that the exe can run as intended. Hope you can help me here, tried to find a solution for hours now...
I had also encountered the same problem and i solved it by implementing the follows:-
Re-installed the pyinstaller module using the latest installer available in github i.e. pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
Re-created the executable package by running the command i.e. pyinstaller --hidden-import=selenium --hidden-import=autoit your [python_file.py]
Copied the installed module i.e. autoit's folder from my PC's directory (C:\Users\\AppData\Local\Programs\Python\Python37\Lib\site-packages) and pasted it inside the [python_file] folder in dist folder which was generated by pyinstaller.
To test the solution, i re-run the generated .exe file in command prompt. Hope this help.
hiddenimports = [ "autoit.init", "autoit.autoit", "autoit.control",
"autoit.process", "autoit.win" ]
datas = [
[
"C:\\Python27\\lib\\site-packages\\autoit\\lib\\AutoItX3_x64.dll",
"autoit\\lib"
]
]
https://raveendran.wordpress.com/2012/06/15/how-to-installregister-autoitx3-dll/
Do this two process your issue will resolve. It resolved me.

How to share my Tkinter app with other users?

I have developed a tkinter application but I need other users (with Windows 10 OS) to use it. Some have a python interpreter installed but others don't. I tried to create an executable through py2exe and auto py-to-exe but none worked. I also tried to run the tkinter through pythonanywhere.com but it also didn't work.
Is there a simply way to share the py files? Perhaps is there a click-to-run environment? What I don't need is to request users to install a full python application such as anaconda or WinPython, as this does not make sense for the users without a python interpreter.
I would use pyinstaller
run cmd.exe as Administartor and type:
pip install pyinstaller
then run with:
pyinstaller --onefile --noconsole --name your_script.py
This creates a single file executable which also includes your Python with all dependencies of your script/project.
If your projects contains external files like images/sounds you might need to edit the spec file as described here.
Full credit to the kid who made this video, it helped me out a lot when I had the same style of problem as you.
https://www.youtube.com/watch?v=pzc4vYqbruk
You'll just have to go through the generated .zip file to find the generated .exe file.

Categories