I have troubleshooted for days with no luck, I hope someone here can help please?
There's lots of discussions about this online all with roughly the same answer so I won't go to much into depth. Here are my system specs for all that I know needs installing.
#478
- Windows 10
- Python Version: 3.10.11
- Pip 23.1.2
- pyusb-1.2.1
- libusb1-3.0.0
I have downloaded and added the libusb-1.0.dll file to C:\Windows\System32\libusb-1.0.dll but I still receive the error that No Backend is available. I have checked and the file is definitely there, I copied it over myself of course.
Here is the simplified code to test for the backend but I will add the full code of my app lower down.
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)
The result in the terminal is:
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
I am pulling my hair out trying to understand why this is still not working, I have directly specified the PATH where the file is and yet it still doesn't find it or am I missing something? I have also added the 32 bit library in SysWOW64 just in case but from what I understood, I'm pretty sure the interpreter isn't searching there.
I am still new to this so apologies if I don't understand the obvious but does anyone know what could be causing this? Any help is much appreciated, cheers.
Here is the full code as it stands but it's practically the same:
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()
**Additionally I have checked the .spec file that is created and again if I understood correctly, it should be finding the libusb-1.0.dd file.
I have also tried adding the .dll file to pyinstallers build directory using this line:
pyinstaller --add-binary "C:\Windows\System32\libusb-1.0.dll;libusb-1.0" --onefile isControllerConnected.py