PyUSB, No backend available. How to specify custom location of libusb?

Viewed 1031

System setup

  • M1 Mac
  • Brew installed libusb /opt/homebrew/Cellar/libusb/1.0.24/lib/libusb-1.0.0.dylib
  • Anacada python 3.10

The No backend available problem see be a known issue with newer python and ARM-based Macs. I am failing to arrive at a solution from that link.

I would like to place a copy of libusb in the project folder and specify that as the backend.

Question: How do I specify the location of libusb-1.0.0.dylib in as a custom backend in find()?

>>> from usb.core import find
>>> f = find(find_all=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/vincentdavis/opt/anaconda3/envs/py310/lib/python3.10/site-packages/usb/core.py", line 1309, in find
    raise NoBackendError('No backend available')
usb.core.NoBackendError: No backend available

I should be able to do something the code below based on this post LINK.

backend = usb.backend.libusb1.get_backend(find_library="/opt/homebrew/Cellar/libusb/1.0.24/lib/libusb-1.0.0.dylib")

f = find(backend=backend, find_all=True)
1 Answers

Solution:

import usb.core
import usb.backend.libusb1
backend = usb.backend.libusb1.get_backend(find_library=lambda x: "/usr/lib/libusb-1.0.so")
dev = usb.core.find(..., backend=backend)

From: https://github.com/walac/pyusb/blob/master/docs/tutorial.rst

Alternative

Try putting instead the contents of /opt/homebrew/Cellar/libusb/1.0.24/lib/ into /usr/local/lib and it should work.

This is one of the paths searched by find_library() of the Python ctypes module on Mac OS (source: https://stackoverflow.com/a/31148541/18197137)

Related