Python PyUSB ValueError:没有可用的后端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25756032/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:36:40  来源:igfitidea点击:

PyUSB ValueError: No backend available

pythonpython-2.7windows-7usbpyusb

提问by Joyful CD

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.

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

I downloaded walac-pyusb-7071ad3 from URL: http://walac.github.io/pyusb

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

I stop at receiving "ValueError: No backend available". Could any Python expert tell me where is wrong?

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

Here is the code:

这是代码:

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)

Here is Python error message:

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

回答by Liviu

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 backendis not valid (None).

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

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.

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

Otherwise, without using find_library, you must have the libusb1 implementation available in the PATHenvironment variable. I did it like this (you can replace os.getcwd()with your location):

否则,在不使用的情况下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

回答by Hayden Thring

I had this trouble, and i switched python libusb wrappers and its gone: https://github.com/vpelletier/python-libusb1

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

回答by Wellington1993

I did: - Download and install libusb-win32-devel-filter-1.2.6.0.exe. It should work.

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

From:

从:

Pyusb on windows - no backend available

Windows 上的 Pyusb - 没有可用的后端

And really works for me.

而且真的对我有用。