问题
I\'m trying to have my python application interface with an NFC device via USB. The best option seems to be pyusb, but I can\'t get it to connect to the libusb backend. I keep getting
ValueError: No backend available
I\'ve looked at the stack trace, and found that usb/backend/libusb10.py
(which is part of pyusb) is trying to load libusb-1.0.dll
to use as the backend, but it can\'t find it. It\'s not that its not in my path, its not on my computer at all!
I have installed libusb-win32 (http://libusb.org/wiki/libusb-win32), but the resulting directory only seems to include libusb0.dll. Where is libusb-1.0.dll???!
I would love to know either where to get that dll, or even a different suggestion to get pyusb to work on Windows 7.
回答1:
Download and install libusb-win32-devel-filter-1.2.6.0.exe. It should work.
回答2:
I had a similar issue recently trying to talk to a USB device I am developing. I scoured the web looking for libusb-1.0.dll's and had no luck. I found source code, but nothing built and ready to install. I ended up installing the libusb-win32 binaries, which is the libusb0.dll.
PyUSB will search for libusb-1.0, libusb0, and openUSB backends.
libusb0.dll was already on my system, but something was still not set up right, do PyUSB was not working.
I followed the directions here to download and install the driver using the GUI tools provided to install the filter driver, and the INF wizard. Note, it didn't work until I ran the INF wizard.
I'm pretty new to programming and I've found the lack of clear documentation/examples to string this all together rather frustrating.
回答3:
I am using Python 2.6.5, libusb-win32-device.bin-0.1.12.1
and pyusb-1.0.0-a0
on a windows XP system and kept receiving ValueError: No backend available
.
Since there wasn't any real help on the web for this problem I spent a lot of time finding that ctypes util.py
uses the Path
variable to find the library file. My path
did not include windows\system32
and PYUSB
didn't find the library. I updated the path
variable and now the USB is working.
回答4:
There's a simpler solution.
Download and unpack to C:\PATH the libusb-1.0.20 from download link
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")
dev = usb.core.find(backend=backend, find_all=True)
Depending on your system, try either MS64 or MS32 version of the .dll
回答5:
"There are two versions of the libusb API: the current libusb-1.0
API, and its legacy predecessor libusb-0.1
." (http://www.libusb.org/) "libusb-win32
is a port of the USB library libusb-0.1
to the Microsoft Windows operating systems". "Download the latest release tarball" from the same page (1.0.9
is the current version) to have libusb-1.0
equivalent, you'll find a folder Win32
, where you'll find your libusb-1.0.dll
to play with! You can even build it: http://www.libusb.org/wiki/windows_backend.
EDIT You have to build it (download from/ http://sourceforge.net/projects/libusb/files/libusb-1.0/) since the tarball is from 2012, while the latest sources are from 2014-06-15.
回答6:
I had the same problem with Windows 10, both Python 2.7.16 and Python 3.7.2. I installed libusb (through python -m pip install libusb
) but the error message remained. Also, the advice above about installing libusb-win32 did not work for me; neither of the 2 links (original post and @beebek's answer) existed.
What did work, however, is the comment by @user1495323 : I copied libusb-1.0.dll
from
C:\Users\username\AppData\Roaming\Python\Python27\site-packages\libusb\_platform\_windows\x64\
to C:\Windows\System32\
回答7:
To connect to your NFC device via USB using PYUSB, you will need to install the backend for that device. I do not think there is any backend for any device other than a libusb device.
To build a backend. You will need to know the driver (.sys file) for your device, so you could write a wrapper DLL to expose functionalities in the device. Your DLL would have to have a method to find device based on PID & VID, another method to open device and another method to send data and so on...
回答8:
Just in case:
I haven't tried this on Windows but I had to set DYLD_LIBRARY_PATH path to circumvent this error on the Macintosh.
export DYLD_LIBRARY_PATH=/opt/local/lib
Discussion on whether or not to set this variable is here.
来源:https://stackoverflow.com/questions/13773132/pyusb-on-windows-no-backend-available