窗口上的Pyusb - 没有可用的后端

use*_*340 26 python libusb windows-7 pyusb

我正在尝试通过USB将我的python应用程序接口与NFC设备连接.最好的选择似乎是pyusb,但我不能让它连接到libusb后端.我一直在

ValueError:没有可用的后端

我查看了堆栈跟踪,发现usb/backend/libusb10.py(这是pyusb的一部分)正在尝试加载libusb-1.0.dll以用作后端,但它无法找到它.这不是它不在我的道路上,它根本不在我的电脑上!

我安装了libusb-win32(http://libusb.org/wiki/libusb-win32),但生成的目录似乎只包含libusb0.dll.libusb-1.0.dll在哪里???

我很想知道在哪里获得该DLL,或者甚至不同的建议让pyusb在Windows 7上运行.

bee*_*bek 16

下载并安装libusb-win32-devel-filter-1.2.6.0.exe.它应该工作.


Ala*_* M. 10

2021 年,该问题在 Windows (Windows 10) 上仍然出现。我通过安装 libusb 路径并将其添加到 Windows 环境解决了pyusb这个libusb 问题

  1. pip install pyusb
  2. pip install libusb
  3. libusb-1.0.dll将自动添加到:

\venv\Lib\site-packages\libusb\_platform\_windows\x64

\venv\Lib\site-packages\libusb\_platform\_windows\x32

  1. 现在只需将这些路径(完整路径)添加到 Windows Path并重新启动 CMD / PyCharm


小智 8

有一个更简单的解决方案。

从下载链接下载 libusb-1.0.20 并将其解压到 C:\PATH

Then try this line:

backend = usb.backend.libusb1.get_backend(find_library=lambda x: "C:\\PATH\\libusb-1.0.20\\MS32\\dll\\libusb-1.0.dll")
usb_devices = usb.core.find(backend=backend, find_all=True)
Run Code Online (Sandbox Code Playgroud)

Depending on your system, try either MS64 or MS32 version of the .dll

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

from infi.devicemanager import DeviceManager

dm = DeviceManager()
devices = dm.all_devices
for d in devices:
    try:
        print(f'{d.friendly_name} : address: {d.address}, bus: {d.bus_number}, location: {d.location}')
    except Exception:
        pass


backend = usb.backend.libusb1.get_backend(find_library=lambda x: "C:\\libusb-1.0.20\\MS32\\dll\\libusb-1.0.dll")
usb_devices = usb.core.find(backend=backend, find_all=True)


def enumerate_usb():  # I use a simple function that scans all known USB connections and saves their info in the file
    with open("EnumerateUSBLog.txt", "w") as wf:
        for i, d in enumerate(usb_devices):
            try:
                wf.write(f"USB Device number {i}:\n")
                wf.write(d._get_full_descriptor_str() + "\n")
                wf.write(d.get_active_configuration() + "\n")
                wf.write("\n")
            except NotImplementedError:
                wf.write(f"Device number {i} is busy.\n\n")
            except usb.core.USBError:
                wf.write(f"Device number {i} is either disconnected or not found.\n\n")
Run Code Online (Sandbox Code Playgroud)


Dav*_* L. 7

我最近有一个类似的问题试图与我正在开发的USB设备交谈.我在网上搜索libusb-1.0.dll并且没有运气.我找到了源代码,但没有构建并准备安装.我最终安装了libusb-win32二进制文件,这是libusb0.dll.

PyUSB将搜索libusb-1.0,libusb0和openUSB后端.

libusb0.dll已经在我的系统上,但是仍然没有正确设置,PyUSB无法正常工作.

我按照这里的说明使用提供的GUI工具下载并安装驱动程序,以安装过滤器驱动程序和INF向导.注意,在我运行INF向导之前它不起作用.

我对编程很陌生,而且我发现缺乏清晰的文档/示例将这一切串联起来相当令人沮丧.


小智 5

我正在使用Python 2.6.5,libusb-win32-device.bin-0.1.12.1pyusb-1.0.0-a0在Windows XP系统上继续接收ValueError: No backend available.

由于网络上没有任何真正的帮助来解决这个问题,我花了很多时间找到ctypes util.py使用Path变量来查找库文件.我path不包括windows\system32PYUSB没找到库.我更新了path变量,现在USB正在工作.


小智 5

我在 Windows 10(Python 2.7.16 和 Python 3.7.2)上遇到了同样的问题。我安装了 libusb (通过python -m pip install libusb)但错误消息仍然存在。另外,上面关于安装 libusb-win32 的建议对我来说不起作用;这两个链接(原始帖子和@beebek 的答案)都不存在。

然而,有效的是 @user1495323 的评论:我libusb-1.0.dll复制 C:\Users\username\AppData\Roaming\Python\Python27\site-packages\libusb\_platform\_windows\x64\C:\Windows\System32\