willwade
willwade

Reputation: 2230

Using a site-packages path for pyinstaller

I'm creating a pyinstaller spec file and need to add a DLL found in a library. This is right now in my own directory here:

a = Analysis(['eyecommand.py'],
         pathex=['.'],
         binaries=["C:\users\wwade\appdata\local\programs\python\python39\lib\site-packages\pyvjoy\utils\x64\vJoyInterface.dll"],
         datas=added_files,
         hiddenimports=["skimage.filters.rank.core_cy_3d","pynput.keyboard._win32", "pynput.mouse._win32"],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher,
         noarchive=True)
         

The problem is I don't want to commit that binary line - it will break on anyone else's machine. Is there a way I can "generically" point to the site-packages dir?

%SITEPACKAGES%\pyvjoy\utils\x64\vJoyInterface.dll

Upvotes: 2

Views: 1361

Answers (1)

gfdsweds
gfdsweds

Reputation: 353

You can use the command line switch --collect-binaries <package> if you want to collect dynamic libraries (like the vJoyInterface.dll you specified). The option is available in PyInstaller 4.3 or above.

Referr to your question, there's something similar here -- a function called get_package_paths() which, you can use it like this:

import os
from PyInstaller.utils.hooks import get_package_paths

pyvjoy_ = get_package_paths('pyvjoy')[1]
os.path.join(pyvjoy_, 'utils', 'x64', 'vJoyInterface.dll')

Meanwhile, the pynput hiddenimports was not needed, as a new hook for pynput was added on pyinstaller-hooks-contrib 2021.3 version.

Upvotes: 1

Related Questions