Add image files while building kivy executable using pyinstaller - python-3.x

I wanted to create an ubuntu executable of my kivy project using pyinstaller. I have used kivy language in the project. With kivy language, I have added some images in the project. Now I wanted to make an executable. It makes executable and the executable also works fine with remaining project, except that images are not visible.
I wanted to add the images which are in the resources folder. I don't really know how could I add these files in the project. I tries --add-data method, but that also doesn't work.

You do need to add the image with either the --add-data or with the datas element in your .spec file. Then you also need to make sure that your code can find the images. I use the following code when my images are in a resources folder:
if getattr(sys, 'frozen', False):
# this is a Pyinstaller bundle
kivy.resources.resource_add_path(sys._MEIPASS)
kivy.resources.resource_add_path(os.path.join(sys._MEIPASS, 'resources'))
And then access the image files using:
image_file_name = kivy.resources.resource_find('someImage.png')

Related

Pyinstaller size changes without any apparent reason

I have a python script using tensorflow, websockets and some other libraries. The problem is when I create a onefile .exe file with pyinstaller which results in a very large size (About 530Mb). Now, I know this is mainly because of Tensorflow, and I am also using a virtual environment, so only the necessary libraries are being packed in the .exe file but for some reason, sometimes when I do a small change in the code an build it again using the same .spec file, importing the same libraries and not even deleting the __pycache__ or the build folders, the .exe file created is way smaller (about 345Mb). I have no idea why this happens and when does this happens. Does anyone has an idea of why this can happen?
PS. I am using pyinstaller 4.10 and pyinstaller-hooks-contrib 2022.2 I tried changing the pyinstaller version, but it does not help on reducing the size of the .exe file

Why executable throws error after cloning from Git repository?

I started using Git recently and I wanted to share my small project. It is a simple decimal conversion program written in Python3. I also coded the GUI using tkinter module.
I want the end-user to run the program as an executable. So I made my .py source file to an executable using pyinstaller. The executable worked perfectly.
I then created a new repository in Git and uploaded my source file and other files created by pyinstaller [build, dist, .spec]. When I tried cloning my repository. the executable throws an error saying:
What am I doing wrong here? Also, is this even the correct way of distributing an open source software?

pyInstaller exe failed because it did not include a module

Situation: Building an EXE from a python script that encrypts things.
Problem: The EXE always fails as it cannot find modules that I have imported (Crypto).
Question: Is there a flag I need to turn on or include to make sure that pyInstaller includes Crypto when building the EXE?
Additional information: The Crypto here refers to pycryptodome
You have to edit your .spec file to include the hiddenimports. As shown here:
hiddenimports=['pycryptodome.apps'],
Run pyinstaller with the .spec command afterwards pyinstaller --name=appname appname.spec
Then you'll have to add the modules that are in your site-package to the root dist application folder. Just copy and paste the entire folder.

Making an Executable out of an entire Python Project

Is there any way I can make an executable out of my Python project? There are many Python scripts that are in my Project and there are SQLite db files as well as other files and folders that are required for the software to run correctly. What is the best way of making this entire project executable?, Should I only make the Python scripts executable?
I have tried Pyinstaller but I am not sure how to bundle all the files into 1 single executable. Shown above is a copy of all the files and folders in my directory.
I think you need to modify the spec file, which PyInstaller creates on a first run. There is a special parameter for data files:
binaries: non-python modules needed by the scripts, including names given by the --add-binary option;
Try adding your database and other data files to this field and they should be included to you package.
For further question I recommend to refer to official documentation and check examples on Github

Why does my pyinstaller created executable require admin privileges?

I've written a Python program which I distribute using pyinstaller. I've been using the onefile option so far to create a standalone executable. That's been great up until now, but as the application has grown the startup time is getting a bit long. I'd also like users to install the application properly to make upgrading simpler.
I've been trying to create a single directory version of the app using pyinstaller's onedir option. However, the resulting .exe file that is created requires admin privileges to run, which the onefile version did not. The program itself doesn't need any such privileges so I assume this is something that pyinstaller is doing. How do I create an application that doesn't require admin privileges?
Additional info:
Python 2.6, pyinstaller v1.4
Application uses PyQt4 and pygame modules.
Trying to create executable for Windows 7.
Using -w pyinstaller option to create a windowless executable.
admin privileges could be asked in few cases:
A. if the executable name contains relevant keywords (like setup, install, update or patch)
B. the application requests it in it's manifest.
C. the .exe file name do not match the name in the manifest file.
if you create a .spec file for your application package, you can add
exe = EXE(
...
manifest=None,
...
)
and it won't ask for password, unless you rename it to setup or install.
I have recently run into this issue, and my experience in solving it was thus:
PyInstaller with --onefile option creates a manifest file in the 'executable'. This manifest file on Windows tells the OS a few things about the application it is bundled with. One of the things it specifies, is the application name/manifest file. The format of the manifest filename is appname.exe.manifest. If your program is frozen with PyInstaller, the executable name that it stores in the manifest will be the name given to the completed EXE under the /dist folder of PyInstaller. IF you rename the EXE, the manifest file packed with it is no longer matching! Therefore, create a manifest file with the same name as the final EXE filename and run PyInstaller with the --manifest option, OR don't rename the EXE that PyInstaller creates.
When you package the PyInstaller project with the custom --manifest, the renamed program no longer requests administrator elevation.

Resources