Bundled Data Directory is not recognized in pyinstaller - python

i'm making a basic OCR with pytesseract, I have this line in my Code
pytesseract.pytesseract.tesseract_cmd = 'data/A/tesseract/tesseract.exe'
and run pyinstaller with
pyinstaller -F --add-data "data;data" OCR.py
but when I launch the application I get this error
data/A/tesseract/tesseract.exe is not installed or it's not in your PATH. See README file for more information.
But if I omit the -F
pyinstaller --add-data "data;data" OCR.py
it just works fine with no errors, But I need it to be a --one-file , How can I Fix it?

The Issue Resolved by adding
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
os.chdir(sys._MEIPASS)
at the beginning of the script

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

After compiling a python script to EXE the Archive method doesn't work

I have a python script that I compiled to an EXE, one of the purposes of it is to extract a 7z file and save it to a destination.
If I'm running it from PyCharm everything works great, this is the code:
def delete_old_version_rename_new(self):
winutils.delete(self.old_version)
print("Extracting...")
Archive(f"{self.new_version}_0.7z").extractall(f"{self.destination}")
print("Finished")
os.rename(self.new_version, self.new_name)
I used pyinstaller to compile the program and used to command pyinstaller --onefile --paths {path to site packages} main.py
Thanks!
Single-file executables self-extract to a temporary folder and run from there, so any relative paths will be relative to that folder not the location of executable you originally ran.
My solution is a code snippet such as this:
if getattr(sys, 'frozen', False):
app_path = os.path.dirname(sys.executable)
else:
app_path = os.path.dirname(os.path.abspath(__file__))
which gives you the location of the executable in the single-file executable case or the location of the script in the case of running from source.
See the PyInstaller documentation here.
Eventually i just used a 7z command line i took from https://superuser.com/questions/95902/7-zip-and-unzipping-from-command-line
and used os.system() to initialize it.
Since my program is command line based it worked even better since its providing a status on the extraction process.
Only downside is i have to move the 7z.exe to the directory of my program.

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

Dask + pyinstaller fails

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.

Categories

Resources