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
Related
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?
Here are my files that i have in a folder ready for compile...
After using pyinstaller i now have my compiled folder complete...
However, as you can see codes.db file is not in the folder as expected!
That is until i click the .exe to launch...then all of a sudden the .exe spits out an empty codes.db file showing 0kb and have no tables. I am assuming at this point that because the codes.db is missing the .exe creates an empty .db with the same name.
How can i make sure that my sqlite3 db is included in the compile? It needs to still have its read/write capability.
EDIT
Im using Windows 10 and Visual Studio 2017.
I don't see your .spec file. Running
pyinstaller file.py
produces a file.spec file. This file should be edited by the user to fit his needs. One hassle free way i found is to have the db in a folder and add the folder, setting datas in analysis to
[
( './db/*', 'db' ),
]
You can view my complete answer on SO here: sqlite + PyQt5 to standalone exe - Python 3.6.3 + Pyinstaller
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')
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
InnoSetup appears to be corrupting my executable when compiling the setup project.
Executing the source file works fine, but executing the file after installation produces Win32 error 1006 "The volume for a file has been externally altered".
I've tried disabling compression and setting various flags, to no avail.
Has anyone experienced this?
UPDATE
Okay there's been some twists to the situation:
At the moment, I can even manually copy a working file to the location it is installed to and get "The volume for a file...". To be clear: I uninstall the application, create the same folder and paste the files there and run.
UPDATE 2
Some more details for those that want it:
The InnoSetup script is compiled by FinalBuilder using output from msbuild, also executed by FinalBuilder, running on my machine with XP SP3. The executable is a C# .Net assembly compiled in configuration Release|AnyCPU. The file works when executed in the folder the Install Script takes it from. It produces the same behaviour on an XP Virtual Machine. The MD5 hashes of the source file and the installed file are the same.
Ok, I just received this same error. I have a config which my executable uses. I looked in my folder a million times - but finally notice the config file was zero length. I corrected the config and the error stopped occurring.
Check the simplest things first... good lucK!
ERROR_FILE_INVALID
1006 (0x3EE): The volume for a file has been externally altered so that the opened file is no longer valid.
I suspect you're having this issue after moving the files to a network share. It seems to me that what's happening is you have an open file-handle - possibly to a temporary file you are creating - and then some other process (perhaps running on a different host) is coming along and renaming or deleting that file or its' parent directory tree.
So my advice is:
Try installing to a local directory
Run after an anti-virus scan, in
safe-mode or on a different machine
to see if there isn't some
background nasty changing
volume/directory properties while
your program is running.
Make sure the program itself isn't doing anything weird with the volume or directory tree you're working with.
Never seen that before. I've got a few questions and suggestions:
- Are you signing the EXE during the compile of the setup? If so, try leaving that part out.
- WHat OS are you installing on or does it happen on all machines you've tried?
- Run the install with the /LOG="c:\install.log" option and post the log. It might show something happening during install.
- Run a byte compare or MD5 check on the source EXE and the installed EXE. Are they the same? Do they have the same version resource?