Dask + pyinstaller fails - python

I am trying to use dask dataframes into a packaged executable using pyinstaller.
I have just
import dask
in my executable and I package it with
pyinstaller scripts.py
When I run it I get that /some/path/dask.yaml is not found.
Does somebody know if there are hidden imports that I should add or how else to solve this issue?

For using dask with PyInstaller you need to add dask.yaml and distributed.yaml to your output executable with add-data flag:
pyinstaller -F --add-data "<python_path>/Lib/site-packages/dask/dask.yaml;./dask" --add-data "<python_path>/Lib/site-packages/distributed/distributed.yaml;./distributed" script.py

If dask is installed in <python_path>\Lib\site-packages\theano, you need to create a hook-dask.py file with this content:
from PyInstaller.utils.hooks import get_package_paths
datas = [(get_package_paths('dask')[1],"dask"),]
and copy this file into your PyInstaller folder:
Lib\site-packages\PyInstaller\hooks
When you run pyinstaller, you need to add the path of site-packages with the -p option:
pyinstaller myApp.py -p <python_path>\Lib\site-packages
It will copy the entire dask folder into your dist output folder.

Related

Cannot open an exe file

import extruct
def main():
input("Hello")
if __name__ == '__main__':
main()
This is the code that I converted into an exe file with pyinstaller. If I open this file now, the exe crashes directly. At the bottom is the message:
FileNotFoundError: [WinError 3] The system cannot find the specified path: 'C:\Users\test\AppData\Local\Temp\_MEI801802\mf2py\backcompat-rules'"
It is definitely because I am importing "extruct". But I need this library for the correct code. Does anyone know how I can fix this error?
I got it to work... these are the steps I took. Im using windows. On another operating system the only changes that need to be made are the virtual environment path to the bakcompat-rules directory.
create a new empty directory and copy and paste your code into main.py file
py -m venv venv
venv/Scripts/activate
py -m pip install --upgrade pip pyinstaller extruct
pyinstaller -F main.py
This will create a main.spec file. open it and at the top paste the following
import os
data = []
parent = "./venv/Lib/site-packages/mf2py/backcompat-rules/"
for item in os.listdir(parent):
path = os.path.join(parent, item)
target = parent
data.append((path, "mf2py/backcompat-rules"))
in same file in Analysis signature change datas=[], to datas=data,
pyinstaller main.spec
dist/main.exe
And it should run fine.

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 failed to execute script: FileNotFoundError: No file or directory: 'C:\\Users\\etc'

I have a python file I am converting to exe via Pyinstaller. The coversion runs fine with no error, however when I run the exe file I get error in line 13 of the python file (line is import librosa). Then I get a bunch of files and then a
FileNotFoundError: No file or directory: 'C:\\Users\\johnny\\Appdata\\Local\\Temp\\_MEI70722\\librosa\\util\\example_data\\registry.txt'.
Also the python file itself runs fine.
Any help would be appreciated
PyInstaller tries to find all the dependencies, however this file is not imported but loaded so it misses it. You can simply force it to add it:
--add-data [path to your python]/Lib/site-packages/librosa/util/example_data;librosa/util/example_data
With The full command be like :
pyinstaller --onefile [YourScript].py --add-data [path to your python]/Lib/site-packages/librosa/util/example_data/registry.txt;librosa/util/example_data
You'll need to specify the data files as PyInstaller hooks.
Create a folder "extra-hooks", and in it a file "hook-librosa.py"
paste these 2 lines in "extra-hooks/hook-librosa.py":
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('librosa')
Then tell PyInstaller where to locate this file with adding 1 of the following to your PyInstaller command:
--additional-hooks=extra-hooks
--additional-hooks-dir "[PATH_TO_YOUR_PROJECT]/axtra-hooks"
The 2nd one worked for me, and I was using auto-py-to-exe, built on PyInstaller.
I guess the file doesn't exist. Open a file manager and copy the directory.
In the PyInstaller, you should type in the python file's name and then --onefile. It makes an .EXE file (if you are on windows) with all the imported files within. You can learn more here: https://pyinstaller.readthedocs.io/en/stable/usage.html

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

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

Categories

Resources