gpt4 book ai didi

python - PyUSB 值错误 : No backend available

转载 作者:太空宇宙 更新时间:2023-11-03 15:11:43 31 4
gpt4 key购买 nike

我在 Win 7 操作系统上运行 Python 2.7.8。我正在尝试通过 PyUSB 与 USB 设备(Numato 32 channel GPIO 设备)通信。

我从 URL 下载了 walac-pyusb-7071ad3:http://walac.github.io/pyusb

我停止接收“ValueError:没有可用的后端”。有哪位 Python 专家能告诉我哪里错了吗?

代码如下:

import sys
import usb
import usb.core
import usb.util
import usb.backend.libusb1

backend = usb.backend.libusb1.get_backend(find_library=lambda C:'\Python27')
numato = usb.core.find(idVendor=00000006,idProduct = 00000000, backend=backend)

这是 Python 错误信息:

Traceback (most recent call last):
File "C:\Python_Yang\PyUSBNumato.py", line 19, in <module>
numato = usb.core.find(idVendor=00000006,idProduct = 00000000, backend=backend)
File "C:\Python_Yang\usb\core.py", line 1199, in find
raise ValueError('No backend available')
ValueError: No backend available

最佳答案

我有同样的错误,但我没有成功使用find_library(TypeError: get_backend() got an unexpected keyword argument 'find_library')。我想,虽然您没有说,但 backend 无效(None)。

路径 C:\Python27 中是否有 libusb1 实现?我想您没有将它安装在 Python 的文件夹中,如果是这样,这就是您的答案:PyUSB backend not accessible .

否则,如果不使用 find_library,您必须在 PATH 环境变量中提供 libusb1 实现。我是这样做的(您可以将 os.getcwd() 替换为您的位置):

def get_backend_libusb01():
libusb01_location = os.getcwd()

# load-library (ctypes.util.find_library) workaround: also search the current folder
is_current_folder_in_search_path = True
if None == usb.backend.libusb0.get_backend():
is_current_folder_in_search_path = libusb01_location in os.environ['PATH']
if not is_current_folder_in_search_path:
os.environ['PATH'] += os.pathsep + libusb01_location

backend = usb.backend.libusb0.get_backend()

if not is_current_folder_in_search_path:
os.environ['PATH'] = os.environ['PATH'].replace(os.pathsep + libusb01_location, "")

return backend

关于python - PyUSB 值错误 : No backend available,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25756032/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com