vpelletier / python-libusb1

Python ctype-based wrapper around libusb1
GNU Lesser General Public License v2.1
168 stars 65 forks source link

Getting OSError in dlopen with the libusb-1.0.dylib installed by homebrew for Apple M1 #73

Closed kenichihiguchi closed 3 years ago

kenichihiguchi commented 3 years ago

Hello, I tried in Apple M1 and got OSError when I load libusb-1.0 library installed by M1 native homebrew. I don't know what causes this error in detail (maybe both of Big Sur and new install path for homebrew; /opt/homebrew/).

reference: MacOS Big Sur - Python ctypes find_library does not find libraries (ssl, CoreFoundation, etc

But it seems that adding symlinked path '/opt/homebrew/opt/libusb/lib/libusb-1.0.dylib' in L167-172 in usb1/libusb1.py will solve this error.

Error Message

Python 3.9.5 (default, Jun  9 2021, 14:53:56) 
[Clang 12.0.5 (clang-1205.0.22.9)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import usb1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/**/python-libusb1/usb1/__init__.py", line 61, in <module>
    from . import libusb1
  File "/Users/**/python-libusb1/usb1/libusb1.py", line 183, in <module>
    libusb = _loadLibrary()
  File "/Users/**/python-libusb1/usb1/libusb1.py", line 157, in _loadLibrary
    return dll_loader(filename, use_errno=True, use_last_error=True)
  File "/opt/homebrew/var/pyenv/versions/3.9.5/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(libusb-1.0.dylib, 6): image not found

Environments