问题描述
我在 Win 7 操作系统上运行 Python 2.7.8.我正在尝试通过 PyUSB 与 USB 设备(Numato 32 通道 GPIO 设备)通信.
I am runing Python 2.7.8 at Win 7 operation system. I am trying to communicate a USB device (Numato 32 channel GPIO device) by PyUSB.
我从以下网址下载了 walac-pyusb-7071ad3:http://walac.github.io/pyusb
I downloaded walac-pyusb-7071ad3 from URL: http://walac.github.io/pyusb
我停止收到ValueError:没有可用的后端".有哪位 Python 专家能告诉我哪里错了吗?
I stop at receiving "ValueError: No backend available". Could any Python expert tell me where is wrong?
代码如下:
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 错误消息:
Here is Python error message:
Traceback (most recent call last):
File "C:Python_YangPyUSBNumato.py", line 19, in <module>
numato = usb.core.find(idVendor=00000006,idProduct = 00000000, backend=backend)
File "C:Python_Yangusbcore.py", line 1199, in find
raise ValueError('No backend available')
ValueError: No backend available
推荐答案
我也有同样的错误,但是我没有成功使用 find_library
(TypeError: get_backend() got an意外的关键字参数find_library"
).我想,虽然你没有说,backend
是无效的(None
).
I had the same error, but I didn't succeed to use find_library
(TypeError: get_backend() got an unexpected keyword argument 'find_library'
).I suppose, although you did not say it, that backend
is not valid (None
).
C:Python27
路径中是否有 libusb1 实现?我想你没有将它安装在 Python 的文件夹中,如果是这样,那就是你的答案:PyUSB 后端不可访问.
Do you have the libusb1 implementation in the path C:Python27
? I suppose you didn't install it in the Python's folder and if so, there's your answer: PyUSB backend not accessible.
否则,在不使用 find_library
的情况下,您必须在 PATH
环境变量中提供 libusb1 实现.我是这样做的(您可以将 os.getcwd()
替换为您的位置):
Otherwise, without using find_library
, you must have the libusb1 implementation available in the PATH
environment variable. I did it like this (you can replace os.getcwd()
with your location):
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
这篇关于PyUSB ValueError:没有可用的后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!