pyinstaller binary not finding library files - python

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.

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.

Python script with file dependencies and output files to executable

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

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

openpyxl not working as EXE

Error message from running my exe:
ModuleNotFoundError: No module named 'openpyxl'
testHi.py
#simple test to see if openpyxl module works
import openpyxl
print ("hi")
input()
hook-openpyxl.py
# taken from pyinstaller dev team, store in same dir as testHi.py
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('openpyxl')
cmd line input:
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
I run the the hiTest and get the error above.
I have looked everywhere for this solution. Can anyone tell me what I am doing wrong.
I fixed my issue by installing it through Pip, rather than install the package through Pycharm, and Pyinstaller was able to find the package.
I got the idea from looking through the text in the command prompt and saw it was loading modules that I had installed via Pip and not through Pycharm.
I was able to get this working using auto-py-to-exe (which uses pyinstaller) by including the following folders/files from my python library into the same folder that I run pyinstaller from:
jdcal.py
openpyxl (folder)
et_xmlfile (folder)
pyinstaller command:
pyinstaller -y -F "[directory]/myscript.py"
Notes on Library Location:
Windows library location for me was: C:\users[username]\AppData\Local\Programs\Python\Python37-32\Lib
The packages were in the "site_packages" folder
use
--hiddenimport openpyxl
long with the previous solutions, it worked for me, I was able to enforce the import of openpyxl.
You was quite close. :-)
I fixed the problem by modifying the "hook-openpyxl.py" file. The command collect_data_files('openpyxl') actually returns an empty list. But there is another command collect_submodules which seems to do what we want. So my "hook-openpyxl.py" file looks like this.
from PyInstaller.utils.hooks import collect_submodules
hiddenimports = collect_submodules('openpyxl')
I placed the "hook-openpyxl.py" file in the same directory like my spec file. In the spec file I set to location of the new hook file
a = Analysis(
...
...
hookspath=['.'],
...
...
...
I guess, you will have the same result with your command line parameter
pyinstaller.exe --onefile --icon=py.ico --additional-hooks-dir=. hiTest.py
My environment
Python=3.8
openpyxl=3.0.10
PyInstaller=4.8

pyexcel hook missing in pyinstaller (unable to load pyexcel)

I am using below code to convert .xls file to .xlsx. It works fine when I run it normally or in debug mode, but If I convert this to the executable file(.exe ) the below code is not working. I guess pyinstaller doesn't have pyexcel hook to load the import. Is there any way I can add this import pyexcel to pyinstaller ??
import pyexcel
pyexcel.save_as(file_name=path_Xls, dest_file_name=path_Xls+'x')
I have Installed pyexcel-xls on my system, still getting this error
Error in console
Short Answer
Please append these lines to your command line:
--hidden-import pyexcel_xls --hidden-import pyexcel_xls.xls
--hidden-import pyexcel_xlsx --hidden-import pyexcel_xlsx.xlsx
Please also note, this solution works only with pyexcel-io v0.3.x and pyexcel v0.4.x
Long Answer
pyexcel-io plugins are lazy-loaded, in other words are imported when they are used. That is why pyinstaller cannot package the hidden imports into your executable by simply reading the source codes without knowing its runtime behaviour.
Here is the documentation on pyexcel-io v0.3.4 with pyinstaller
More information
With the latest pyexcel v0.5.0 and pyexcel-io 0.4.0, there are more options to be appended, I am afraid, because all built-in plugins become lazy-loaded too. Here are the corresponding documentations: pyinstaller on pyexcel and pyexcel-io

Categories

Resources