PyUSB值错误:没有可用的后端

2024-05-19 03:02:06 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

我停止接收“ValueError:No backend available”。有没有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

Tags: nocoreimportbackendfindfileusbpyusb
3条回答

我遇到了这个问题,我换了python libusb包装器,它就不见了:https://github.com/vpelletier/python-libusb1

我做到了: -下载并安装libusb-win32-devel-filter-1.2.6.0.exe。它应该有用。

发件人:

Pyusb on windows - no backend available

真的对我有用。

我也有同样的错误,但是我没有成功地使用find_libraryTypeError: 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

相关问题 更多 >

    热门问题