指定路径后仍提示No Backend Available问题求助
求助:PyUSB始终提示“No Backend is available”问题
我已排查多日但毫无进展,希望能在这里获得帮助。网上关于该问题的讨论众多且答案大致相同,因此我不再赘述细节,以下是我的系统环境信息:
- Windows 10
- Python版本:3.10.11
- Pip版本:23.1.2
- pyusb-1.2.1
- libusb1-3.0.0
我已下载libusb-1.0.dll文件并将其复制到C:\Windows\System32\libusb-1.0.dll,但仍收到No Backend is available的错误提示,我确认该文件确实存在于指定路径中。
测试后端的简化代码
import usb.core import usb.backend.libusb1 backend = usb.backend.libusb1.get_backend(find_library=lambda x:"C:\\Windows\\System32\\libusb-1.0.dll") print(backend) dev = usb.core.find(backend=backend, find_all=True) print(dev)
终端运行报错信息
Traceback (most recent call last): File "f:\Software Development\Controller Detection Programme\pythonLocator.py", line 6, in dev = usb.core.find(backend=backend, find_all=True) File "C:\Users\dmitr\AppData\Local\Programs\Python\Python310\lib\site-packages\usb\core.py", line 1309, in find raise NoBackendError('No backend available') usb.core.NoBackendError: No backend available
我绞尽脑汁也无法理解为何问题仍未解决,我已直接指定了文件路径,但系统仍无法找到它,或许我遗漏了什么?我还将32位库添加到了SysWOW64目录以防万一,但据我所知,解释器应该不会搜索该路径。
我是新手,若无法理解一些明显问题还请见谅,有人知道导致该问题的原因吗?非常感谢您的帮助。
完整程序代码
import sys import usb.core import usb.backend.libusb1 import tkinter as tk import tkinter.messagebox as tkmb import time #be = libusb1.get_backend() #devbe = usb.core.find(backend=be) window = tk.Tk() window.title("Controller Detection") window.geometry("700x500") isConnected = False starttime = time.time() label = tk.Label(window, text="Click the Button to start the controller check", font=('Calibri 15 bold')) label.pack(pady=20) def checkForController(): backend = usb.backend.libusb1.get_backend(find_library=lambda x:"C:\\Windows\\System32\\libusb-1.0.dll") #find all USB devices dev = usb.core.find(find_all=True, backend=backend) while True: time.sleep(4 - ((time.time() - starttime) % 2)) # loop through devices, checking for idProduct 3302, i.e. the controller for cfg in dev: if cfg.idProduct == 3302: print("Device connected") label["text"] = "Device Connected" isConnected = True break if isConnected == False: print("Device is Not Connected") label["text"] = "Device Not Connected" isConnected == False btn1 = tk.Button(window, text="Button1", command=checkForController) btn1.pack(pady=20) window.mainloop()
尝试过的PyInstaller打包操作
我检查了生成的.spec文件,据我理解它应该能找到libusb-1.0.dll文件。我还尝试通过以下命令将.dll文件添加到PyInstaller的构建目录:
pyinstaller --add-binary "C:\Windows\System32\libusb-1.0.dll;libusb-1.0" --onefile isControllerConnected.py
内容的提问来源于stack exchange,提问作者Dmitry
相关产品推荐
相关产品推荐

