PyUSB,没有可用的后端.如何指定libusb的自定义位置



系统设置

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

没有可用的后端问题请参阅,这是较新的python和基于ARM的Mac的已知问题。我没能从这个环节找到解决方案。

我想在项目文件夹中放置libusb的副本,并将其指定为后端。

问题:如何在find((中将libusb-1.0.0.dylib的位置指定为自定义后端?

>>> 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

我应该能够做一些事情,下面的代码基于这个帖子链接。

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)

解决方案:

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)

发件人:https://github.com/walac/pyusb/blob/master/docs/tutorial.rst

替代

试着将/opt/homebrew/Cellar/libusb/1.0.24/lib/的内容放入/usr/local/lib中,它应该可以工作。

这是Mac OS上Python ctypes模块的find_library((搜索的路径之一(来源:https://stackoverflow.com/a/31148541/18197137)

最新更新