pythonpyinstallermediapipe

script using mediapipe breaks after making it executable with pyinstaller - FileNotFoundError: The path does not exist


I made a desktop-application using PyQT5 library. The main library that I am using is opencv-python-headless, mediapipe and pyserial. So, my python script does exactly what it should do and works perfectly. But after I make it executable with pyinstaller it breaks. Mainly the mediapipe library throws this error:

Exception in thread Thread-3 (getReady_screen):
Traceback (most recent call last):
  File "threading.py", line 1016, in _bootstrap_inner
  File "threading.py", line 953, in run
  File "app.py", line 344, in getReady_screen
  File "app.py", line 193, in detect_squat
  File "mediapipe/python/solutions/pose.py", line 146, in __init__
  File "mediapipe/python/solution_base.py", line 271, in __init__
FileNotFoundError: The path does not exist.

I tried to make my script executable with this two commands, both of them throws the same error:

pyinstaller --onedir app.py 
pyinstaller --onefile app.py 

This is the user-name and path to my directory squat@squat-OptiPlex-3050:~/squat-counting-application$

These are the contents in my requirements.txt file:

absl-py==2.0.0
attrs==23.1.0
cffi==1.16.0
contourpy==1.1.1
cycler==0.12.1
docopt==0.6.2
flatbuffers==23.5.26
fonttools==4.46.0
importlib-resources==6.1.1
kiwisolver==1.4.5
matplotlib==3.7.4
mediapipe==0.10.8
num2words==0.5.13
numpy==1.24.4
opencv-python-headless==4.8.1.78
packaging==23.2
Pillow==10.1.0
protobuf==3.20.3
pycparser==2.21
pyparsing==3.1.1
PyQt5==5.15.10
PyQt5-Qt5==5.15.2
PyQt5-sip==12.13.0
pyqtspinner==2.0.0
pyserial==3.5
python-dateutil==2.8.2
PyYAML==6.0.1
six==1.16.0
sounddevice==0.4.6
zipp==3.17.0
My system specs are:

Solution

  • I checked similar other solutions here, but they were for macos and windows which didn't help in my case. I am using popos-22.04. Here or in ubuntu-22.04 changing the .spec file doesn't solve anything.

    Moreover, I found out there are some dependency issues with mediapipe==0.10.9 and pyQt5==5.15.10 library too. Apparently, they don't support the same opencv package. With pyqt5 I was facing this issue, that comes from the opencv dependency conflict with mediapipe:

    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/squat/.local/lib/python3.10/site-packages/cv2/qt/plugins" even though it was found. 
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem. 
    
    Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl. 
    
    Aborted (core dumped).
    

    This dependency issue also can be solve my uninstalling all opencv libraries and installing opencv-python-headless again, but it creates issues while you want to test your application onto a new machine. You have do this manually on new system too. So, just use pyQt6.

    So, here is how I solved this issue for ubuntu-22.04 and popos-22.04:

    /home/arrafi/squat-counting-application/venv/lib/python3.10/site-packages/mediapipe
    
    pyinstaller --onedir --add-data "/home/arrafi/squat-counting-application/venv/lib/python3.10/site-packages/mediapipe:mediapipe/" --icon icon.ico app.py
    

    Now, my app is building without any issue and also running correctly on other machines too.

    so, here --add-data argument put you own path to where mediapipe is installed:

    pyinstaller --onedir --add-data "your_mediapipe_installed_path:mediapipe/" --icon icon.ico app.py