Joy*_* CD 5 python usb windows-7 python-2.7 pyusb
我在 Win 7 操作系统上运行 Python 2.7.8。我正在尝试通过 PyUSB 通信 USB 设备(Numato 32 通道 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)
Run Code Online (Sandbox Code Playgroud)
这是 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
Run Code Online (Sandbox Code Playgroud)
我也遇到了同样的错误,但是我没有成功使用find_library(TypeError: get_backend() got an unexpected keyword argument 'find_library')。我想,虽然你没有说出来,但这backend不是有效的(None)。
你的路径中有 libusb1 实现吗C:\Python27?我想你没有将它安装在Python的文件夹中,如果是这样,那就是你的答案:PyUSB backend not accessed。
否则,在不使用 的情况下find_library,您必须在环境变量中提供可用的 libusb1 实现PATH。我是这样做的(你可以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
Run Code Online (Sandbox Code Playgroud)