1

I have created a virtual mouse (uses opencv & mediapipe to track your hand and apply movement to the mouse). The problem is that upon running the exe I get an error, because it can no longer access the mediapipe files.

Specifically, it couldn't access two, both found in C:\Users\hchap\AppData\Local\Programs\Python\Python310\Lib\site-packages\mediapipe\python\solutions

Anybody know how to include mediapipe's dependencies (the files) into an exe?

Hchap
  • 58
  • 6

1 Answers1

1

If you want to put all these files together, you gonna have to tell PyInstaller to include them, lets do that by creating a spec file.

First we generate it

pyinstaller --name=my_script my_script.py

then we modify our my_script.spec so that for the a = Analysis() we have something like the code below, modify the paths as needed.

a = Analysis(['my_script.py'],
             pathex=['path\\to\\your\\script'],
             binaries=[],
             datas=[
                 ('C:\\Users\\hchap\\AppData\\Local\\Programs\\Python\\Python310\\Lib\\site-packages\\mediapipe\\python\\solutions\\*.*', 'mediapipe\\python\\solutions'),
                 # Add any other necessary directories here.
             ],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

then we can rebuild our application with our spec file

pyinstaller my_script.spec

Now the resulting executable have the necessary MediaPipe files bundled with it.

Saxtheowl
  • 4,136
  • 5
  • 23
  • 32