Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library lookup doesn't work with custom path #50

Open
cdlm opened this issue Jun 28, 2021 · 3 comments · May be fixed by #51
Open

Library lookup doesn't work with custom path #50

cdlm opened this issue Jun 28, 2021 · 3 comments · May be fixed by #51

Comments

@cdlm
Copy link

cdlm commented Jun 28, 2021

I have hidapi installed via brew under a custom prefix:

$ ls -l /opt/brew/lib/libhidapi*
lrwxr-xr-x 1 damien admin 45 Jun 13 19:25 /opt/brew/lib/libhidapi.0.dylib -> ../Cellar/hidapi/0.10.1/lib/libhidapi.0.dylib
lrwxr-xr-x 1 damien admin 39 Jun 13 19:25 /opt/brew/lib/libhidapi.a -> ../Cellar/hidapi/0.10.1/lib/libhidapi.a
lrwxr-xr-x 1 damien admin 43 Jun 13 19:25 /opt/brew/lib/libhidapi.dylib -> ../Cellar/hidapi/0.10.1/lib/libhidapi.dylib

That breaks qmk because it can't find it.

$ qmk compile
Error: %s: %s ('ImportError', ImportError('Unable to load any of the following libraries:libhidapi-hidraw.so libhidapi-hidraw.so.0 libhidapi-libusb.so libhidapi-libusb.so.0 libhidapi-iohidmanager.so libhidapi-iohidmanager.so.0 libhidapi.dylib hidapi.dll libhidapi-0.dll'))
Traceback (most recent call last):
  File "/opt/brew/Cellar/qmk/0.1.0/libexec/lib/python3.9/site-packages/qmk_cli/script_qmk.py", line 76, in main
    import qmk.cli  # noqa
  File "/Users/damien/Repositories/custom-keyboards/qmk_firmware/lib/python/qmk/cli/__init__.py", line 191, in <module>
    __import__(subcommand)
  File "/Users/damien/Repositories/custom-keyboards/qmk_firmware/lib/python/qmk/cli/console.py", line 9, in <module>
    import hid
  File "/opt/brew/Cellar/qmk/0.1.0/libexec/lib/python3.9/site-packages/hid/__init__.py", line 30, in <module>
    raise ImportError(error)
ImportError: Unable to load any of the following libraries:libhidapi-hidraw.so libhidapi-hidraw.so.0 libhidapi-libusb.so libhidapi-libusb.so.0 libhidapi-iohidmanager.so libhidapi-iohidmanager.so.0 libhidapi.dylib hidapi.dll libhidapi-0.dll
@apmorton
Copy link
Owner

apmorton commented Jun 28, 2021 via email

@cdlm cdlm linked a pull request Jun 28, 2021 that will close this issue
@cdlm
Copy link
Author

cdlm commented Jun 28, 2021

I had tried that before with DYLD_LIBRARY_PATH, and now with LD_LIBRARY_PATH, but that doesn't help (QMK fails to start and demands that I run its install script again). My changes in #51 make it work fine.

@mfncooper
Copy link

When setting DYLD_LIBRARY_PATH (or LD_LIBRARY_PATH ) doesn't work, it is quite likely that the issue is SIP (macOS System Integrity Protection). Basically, with SIP enabled, which is the default on modern Macs, those particular variables will never be passed to another process, so setting them is useless. See:

https://developer.apple.com/library/archive/documentation/Security/Conceptual/System_Integrity_Protection_Guide/RuntimeProtections/RuntimeProtections.html

Spawning children processes of processes restricted by System Integrity Protection, such as by launching a helper process in a bundle with NSTask or calling the exec(2) command, resets the Mach special ports of that child process. Any dynamic linker (dyld) environment variables, such as DYLD_LIBRARY_PATH, are purged when launching protected processes.

The path can be set from Python before attempting to load the library, like so:

import os
os.environ['DYLD_LIBRARY_PATH'] = '/opt/homebrew/lib'
import hid

Ugly, but it works.

The alternative seems to be to disable SIP on the machine, which doesn't seem like a good idea at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants