Python script with file dependencies and output files to executable - python

So I have a GUI script file that works well when running from command line. However when I use pyinstaller and auto-py-to-exe, I keep getting
MEIPASSxxx file exists but should not
errors
My folder is
-ML Model Output
-sun valley ttk theme
-icon.ico
-GUI_output_1.csv
-GUI_output_2.csv
-GUI_script.py
Essentially the script.py is a Tkinter GUI. It takes user input and runs it through the ML Model. Based on the ML classification the user input goes into one of the CSV files. The idea is that the user should be able to access the csv to use the data for next steps.
I’ve tried different versions of pyinstaller and auto-py-to-exe. —one file, —one dir, adding the additional files and folders. All of them basically gives this error.
I understand the meipass is a temp folder where pyinstaller unpacks data. But I’ve gone to the temp folder and deleted the folders. I am not sure how to fix this, all examples I’ve found are using very simple examples. Any advice for how to go about this? I need to get a single executable to share with client.

So I was able to fix this using the following code:
pyinstaller --noconfirm --onedir --windowed
--icon "C:[path]/icon.ico"
--add-data "C:[path]/GUI_output_1.csv;."
--add-data "C:[path]/GUI_output_2.csv;."
--add-data "C:[path]/icon.ico;."
--add-data "C:[path]/Model;Model/"
--add-data "C:[path]/Sun-Valley-ttk-theme-master;Sun-Valley-ttk-theme-master/"
--paths "C:[path]/anaconda3/Lib/site-packages"
--hidden-import "pytorch" --hidden-import "tkinter
--collect-data "torch"
--copy-metadata "torch" --copy-metadata "tqdm" --copy-metadata "regex" --copy-metadata "sacremoses" --copy-metadata "requests" --copy-metadata "packaging" --copy-metadata "filelock" --copy-metadata "numpy" --copy-metadata "tokenizers" --copy-metadata "importlib_metadata" "
"C:[path]/GUI_script.py"
The above was all one line, but broke the code up into different lines so that it would be easy to read for other users

Related

Pyinstaller compile error on unused library

AssertionError: Failed to determine matplotlib's data directory!
Im not using maptolib anywhere and there is another error assiciated with it
File "C:\Python310\lib\site-packages\matplotlib\colors.py", line 51, in <module>
from PIL import Image
ModuleNotFoundError: No module named 'PIL'
My command
pyinstaller --noconfirm --onefile -w --console --name "Project1" --add-data "C:/Users/user/Desktop/bot/app.py;." --add-data "C:/Users/user/Desktop/bot/czgen.py;." --add-data "C:/Users/user/Desktop/bot/sk.py;." --add-data "C:/Users/user/Desktop/bot/site.py;." --hidden-import "colorama" "C:/Users/user/Desktop/bot/main.py"
Any ideas?
i think one of the modules you used needs matplotlib, so check if everything works. otherwise, i would suggest to clear out the virtual enviroment and downloading everything back. this way the issue will be inside of the code and not in pyinstaller, therefore it'll be easier to debug and find the issue.

no module named cv2 pyinstaller

i made a python script(flask) that use html and generate a local host link to open my website i also imported some deep learning models to my project what i want is i want to make an exe file that gives me the output is the local host link so i used this command to make it
pyinstaller --onefile main.py
but when i run my exe file it gives me this error
no module named cv2
i also tried this command
pyinstaller spec_an_API.py --onefile --add-data "templates";"templates" --add-data "static";"static"
but same problem
not that my program has no errors i tried to run it from pycharm and it works well

Pyinstaller --hidden-imports not wirking

I'm trying to build an exe file from a python game using PyBox2D and Pyglet.
When I build the exe there occurs an error that a module cannot be imported:
Unable to import the back-end pyglet: module 'gui.backends' has no attribute 'pyglet_framework'
I guess this happens because this file only gets imported indirectly/hidden from another file with __import__()
This is my project hierarchy:
I've tried to add the file to pyinstaller on multiple ways. From the directory /SpaceJam/building I've tried calling:
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="gui/framework/backends/pyglet_framework.py"
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="../gui/framework/backends/pyglet_framework.py"
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="../gui/framework/backends/pyglet_framework"
pyinstaller.exe --onefile "../game/spacejam.py" --hidden-import="../gui/framework/backends/*"
but none of that seemed to change anything in the error message.
I feel like I'm missing something obvious. Does somebody have an idea what I might be doing wrong or why the --hidden-import argument doesn't seem to work?
That argument expects a module name, not a filesystem path. How would you import it?
I'm not totally clear on how your project is set up, but try
--hidden-import gui.backends.pyglet_framework

pyinstaller binary not finding library files

I have a python program I'm converting to a single binary file and then moving to a different platform. When I run the binary it's complaining about a missing library. What's confusing is that it is present. How can I fix this error?
Binary Created:
pyinstaller --hidden-import pyaudio --hidden-import wave --hidden-import Logger --hidden-import json --hidden-import websockets --hidden-import asyncio --onefile Run_SD.py
Running Binary (on different platform):
/lib/libcrypto.so.1.1
/usr/lib/libcrypto.so.1.1
~$ ./Run_SD
[3656] Error loading Python lib '/tmp/_MEIgqfADy/libpython3.7m.so.1.0': dlopen: libcrypt.so.1: cannot open shared object file: No such file or directory
But the library is on the platform:
/lib/libcrypto.so.1.1
/usr/lib/libcrypto.so.1.1
(on the source plaform it's at: /usr/lib/aarch64-linux-gnu/libcrypto.so.1.1 )
I have found a solution .. not sure it's the correct one, but it works.
I copied the missing file into the source directory and then added --add-binary libcrypt.so.1:. to the command line which includes the file into the build and then all works.

how to solve fbs error 'Can not find path ./libshiboken2.abi3.5.13.dylib'?

I have been able to freeze a Python/PySide2 script with fbs on macOS, and the app seems to work.
However, I got some errors from the freeze process stating:
Can not find path ./libshiboken2.abi3.5.13.dylib.
Does anyone know how to fix that?
Try to use the --runtime-tmpdir because while running the generated exe file it needs this file libshiboken2.abi3.5.13.dylib and unable hook that file.
Solution: use --add-data & --runtime-tmpdir to pyinstaller command line.
pyinstaller -F --add-data "path/libshiboken2.abi3.5.13.dylib":"**PATH"
--runtime-tmpdir temp_dir_name your_program.py
here PATH = the directory name of that file looking for.-F = one file

Categories

Resources