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 it’s not in my path, it’s not on my computer at all!
I have installed 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.
wovano
4,5725 gold badges22 silver badges50 bronze badges
asked Dec 8, 2012 at 0:25
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.
answered Dec 26, 2012 at 22:04
3
2021 and the problem still occurs on Windows (Windows 10). I solved it by installing pyusb
and libusb
and adding libusb path to Windows environment:
pip install pyusb
pip install libusb
libusb-1.0.dll
will be automatically added to:
\venv\Lib\site-packages\libusb\_platform\_windows\x64
and
\venv\Lib\site-packages\libusb\_platform\_windows\x32
- Now just add those paths (the full path) to Windows Path and restart CMD / PyCharm.
answered Jun 21, 2021 at 7:56
Alaa M.Alaa M.
4,97110 gold badges54 silver badges95 bronze badges
5
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.
Jules
14.2k13 gold badges56 silver badges102 bronze badges
answered Apr 30, 2013 at 20:45
George GGeorge G
611 silver badge1 bronze badge
2
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") usb_devices = usb.core.find(backend=backend, find_all=True)
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")
Neuron
5,1615 gold badges38 silver badges59 bronze badges
answered Oct 3, 2019 at 6:36
0
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\
answered Mar 15, 2019 at 12:23
user9393931user9393931
1772 silver badges9 bronze badges
0
-
download the latest libusb
Download libusb
Copy MS32\dll\libusb-1.0.dll to C:\Windows\SysWOW64
Copy MS64\dll\libusb-1.0.dll to C:\Windows\System32
3.
pip install libusb
Copy MS32\dll\libusb-1.0.dll to C:\Python\Python37-32\Lib\site-packages\libusb_platform_windows\x86
Copy MS64\dll\libusb-1.0.dll to C:\Python\Python37-32\Lib\site-packages\libusb_platform_windows\x64
This method works for me.
answered Jun 26, 2020 at 2:32
Jacky YanJacky Yan
1111 silver badge4 bronze badges
0
Had some problems with backendnotavailable at 2022 when I install pyusb and libusb on my Windows x64.
I’ve found a way to solve it reading -> Github solve explaining
To solve, first you need copy path to libusb-1.0.dll (..\envs<your_env_name>\Lib\site-packages\libusb_platform_windows\x64) at system’s PATH variable.
Secondly restart IDE.
Third try to get_backend use usb.backend:
import usb.core
from usb.backend import libusb1
# it should find libusb-1.0.dll at our path variable
back = libusb1.get_backend()
print(type(back)) # return: <class 'usb.backend.libusb1._LibUSB'>
dev = usb.core.find(backend=back)
print(type(dev)) # return: <class 'usb.core.Device'>
# flag 'find_all=True' would return generator
# reprecent connected usb devices
dev_list = usb.core.find(find_all=True, backend=back)
print(type(dev_list)) # return: <class 'generator'>
If back is a NoneType
, that means get_backend()
hasn’t found libusb-1.0.dll or found the wrong usblib (and that was my problem — I copied atPATH variable path to _x86 file, on my x64 machine).
Another way to solve it -> copy libusb-1.0.dll from (.._x64\libusb-1.0.dll) to (C:\Windows\System32).
ouflak
2,45810 gold badges44 silver badges49 bronze badges
answered Jan 14, 2022 at 12:01
«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.
answered Sep 16, 2014 at 12:49
LiviuLiviu
1,8592 gold badges22 silver badges48 bronze badges
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…
answered Aug 6, 2014 at 18:55
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.
answered Mar 15, 2015 at 9:15
fixxxerfixxxer
15.6k15 gold badges59 silver badges76 bronze badges
The libusb backend is initialized by the python script in /usb path,by loading the binary DLL from Windows PATH,if it’s missed or installed by the zadig’s dummy DLL,it will complained about this.Because the DLL installed by zadig doesn’t exports any symbol to outside wolrd(dummy one I guess)
answered Jan 2, 2021 at 10:12
This is a mix from multiple answers and here a ready-to-use solution for Windows x64 bit:
-
Run:
pip install pyusb pip install libusb
-
Do:
import usb.backend.libusb1 backend = usb.backend.libusb1.get_backend(find_library=lambda x: r"C:\Python38\Lib\site-packages\libusb\_platform\_windows\x64\libusb-1.0.dll") # adapt to your path usb_devices = usb.core.find(backend=backend, find_all=True) for usb_device in usb_devices: print(usb_device)
Done!
answered Sep 6 at 14:39
BasjBasj
41.6k100 gold badges389 silver badges677 bronze badges
2
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 it’s not in my path, it’s not on my computer at all!
I have installed 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.
wovano
4,5725 gold badges22 silver badges50 bronze badges
asked Dec 8, 2012 at 0:25
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.
answered Dec 26, 2012 at 22:04
3
2021 and the problem still occurs on Windows (Windows 10). I solved it by installing pyusb
and libusb
and adding libusb path to Windows environment:
pip install pyusb
pip install libusb
libusb-1.0.dll
will be automatically added to:
\venv\Lib\site-packages\libusb\_platform\_windows\x64
and
\venv\Lib\site-packages\libusb\_platform\_windows\x32
- Now just add those paths (the full path) to Windows Path and restart CMD / PyCharm.
answered Jun 21, 2021 at 7:56
Alaa M.Alaa M.
4,97110 gold badges54 silver badges95 bronze badges
5
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.
Jules
14.2k13 gold badges56 silver badges102 bronze badges
answered Apr 30, 2013 at 20:45
George GGeorge G
611 silver badge1 bronze badge
2
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") usb_devices = usb.core.find(backend=backend, find_all=True)
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")
Neuron
5,1615 gold badges38 silver badges59 bronze badges
answered Oct 3, 2019 at 6:36
0
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\
answered Mar 15, 2019 at 12:23
user9393931user9393931
1772 silver badges9 bronze badges
0
-
download the latest libusb
Download libusb
Copy MS32\dll\libusb-1.0.dll to C:\Windows\SysWOW64
Copy MS64\dll\libusb-1.0.dll to C:\Windows\System32
3.
pip install libusb
Copy MS32\dll\libusb-1.0.dll to C:\Python\Python37-32\Lib\site-packages\libusb_platform_windows\x86
Copy MS64\dll\libusb-1.0.dll to C:\Python\Python37-32\Lib\site-packages\libusb_platform_windows\x64
This method works for me.
answered Jun 26, 2020 at 2:32
Jacky YanJacky Yan
1111 silver badge4 bronze badges
0
Had some problems with backendnotavailable at 2022 when I install pyusb and libusb on my Windows x64.
I’ve found a way to solve it reading -> Github solve explaining
To solve, first you need copy path to libusb-1.0.dll (..\envs<your_env_name>\Lib\site-packages\libusb_platform_windows\x64) at system’s PATH variable.
Secondly restart IDE.
Third try to get_backend use usb.backend:
import usb.core
from usb.backend import libusb1
# it should find libusb-1.0.dll at our path variable
back = libusb1.get_backend()
print(type(back)) # return: <class 'usb.backend.libusb1._LibUSB'>
dev = usb.core.find(backend=back)
print(type(dev)) # return: <class 'usb.core.Device'>
# flag 'find_all=True' would return generator
# reprecent connected usb devices
dev_list = usb.core.find(find_all=True, backend=back)
print(type(dev_list)) # return: <class 'generator'>
If back is a NoneType
, that means get_backend()
hasn’t found libusb-1.0.dll or found the wrong usblib (and that was my problem — I copied atPATH variable path to _x86 file, on my x64 machine).
Another way to solve it -> copy libusb-1.0.dll from (.._x64\libusb-1.0.dll) to (C:\Windows\System32).
ouflak
2,45810 gold badges44 silver badges49 bronze badges
answered Jan 14, 2022 at 12:01
«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.
answered Sep 16, 2014 at 12:49
LiviuLiviu
1,8592 gold badges22 silver badges48 bronze badges
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…
answered Aug 6, 2014 at 18:55
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.
answered Mar 15, 2015 at 9:15
fixxxerfixxxer
15.6k15 gold badges59 silver badges76 bronze badges
The libusb backend is initialized by the python script in /usb path,by loading the binary DLL from Windows PATH,if it’s missed or installed by the zadig’s dummy DLL,it will complained about this.Because the DLL installed by zadig doesn’t exports any symbol to outside wolrd(dummy one I guess)
answered Jan 2, 2021 at 10:12
This is a mix from multiple answers and here a ready-to-use solution for Windows x64 bit:
-
Run:
pip install pyusb pip install libusb
-
Do:
import usb.backend.libusb1 backend = usb.backend.libusb1.get_backend(find_library=lambda x: r"C:\Python38\Lib\site-packages\libusb\_platform\_windows\x64\libusb-1.0.dll") # adapt to your path usb_devices = usb.core.find(backend=backend, find_all=True) for usb_device in usb_devices: print(usb_device)
Done!
answered Sep 6 at 14:39
BasjBasj
41.6k100 gold badges389 silver badges677 bronze badges
2
Answer by Austin Newton
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.,ValueError: No backend available,Making statements based on opinion; back them up with references or personal experience.,Find centralized, trusted content and collaborate around the technologies you use most.
Update of 17/01/2020, after a request to share more code:
import usb.core
import usb.util
from infi.devicemanager import DeviceManager
dm = DeviceManager()
devices = dm.all_devices
for i in devices:
try:
print ('{} : address: {}, bus: {}, location: {}'.format(i.friendly_name, i.address, i.bus_number, i.location))
except Exception:
pass
import usb.backend.libusb1
backend = usb.backend.libusb1.get_backend(find_library=lambda x: "C:\\libusb-1.0.20\\MS32\\dll\\libusb-1.0.dll")
dev = usb.core.find(backend=backend, find_all=True)
def EnumerateUSB(): #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:
counter = 0
for d in dev:
try:
wf.write("USB Device number " + str(counter) + ":" + "\n")
wf.write(d._get_full_descriptor_str() + "\n")
wf.write(d.get_active_configuration() + "\n")
wf.write("\n")
counter += 1
except NotImplementedError:
wf.write("Device number " + str(counter) + "is busy." + "\n")
wf.write("\n")
counter += 1
except usb.core.USBError:
wf.write("Device number " + str(counter) + " is either disconnected or not found." + "\n")
wf.write("\n")
counter += 1
wf.close()
Answer by Dayana Shaw
Pyusb on windows — no backend available
Pyusb on windows 8.1 — no backend available — how to install libusb?
libusb installed- but pyUSB backend not found
PyUSB ValueError: No backend available
PyUSB backend not accessible,Pyusb on windows 8.1 — no backend available — how to install libusb?,libusb installed- but pyUSB backend not found,PyUSB ValueError: No backend available
python3 setup.py build
sudo python3 setup.py install
Answer by Jaxx Lawson
“Error: No backend available”,On Linux: export LD_LIBRARY_PATH=<path>,libusb native library cannot be loaded. Try helping the dynamic loader:,On Linux: export LD_LIBRARY_PATH=<path>
where <path> is the directory containing the libusb-1.*.so
library file
sudo kextunload [-v] -bundle com.apple.driver.AppleUSBFTDI
- Главная
- Пользователи
- Найти
- Войти
- Sign up
- Вы не вошли.
Уведомления
- Начало
- » Python для экспертов
- » Pyusb — Error «no backend available»
#1 Ноя. 5, 2019 21:21:10
Pyusb — Error «no backend available»
Привет. Использую pydroid3 на планшете huawei. Установил модуль pyusb. Пытался пробовать выполнить простейшие примеры из инета. Результат — Error “no backend available”. Как не пытался не получается. Что делать? Может проблема права ROOT нужны? Или не в этом дело? Через файловые менеджеры флешки подключённые видит, читает, пишет. А через pydroid3 не могу с usb портом работать.
Офлайн
- Пожаловаться
- Начало
- » Python для экспертов
-
» Pyusb — Error «no backend available»
Board footer
Reporting a bug
Please do not contact the author by email. The preferered method to report bugs
and/or enhancement requests is through
GitHub.
Please be sure to read the next sections before reporting a new issue.
Logging
FTDI uses the pyftdi logger.
It emits log messages with raw payload bytes at DEBUG level, and data loss
at ERROR level.
Common error messages
“Error: No backend available”
libusb native library cannot be loaded. Try helping the dynamic loader:
-
On Linux:
export LD_LIBRARY_PATH=<path>
where
<path>
is the directory containing thelibusb-1.*.so
library file -
On macOS:
export DYLD_LIBRARY_PATH=.../lib
where
<path>
is the directory containing thelibusb-1.*.dylib
library file -
On Windows:
Try to copy the USB dll where the Python executable is installed, along
with the other Python DLLs.If this happens while using an exe created by pyinstaller:
copy C:\Windows\System32\libusb0.dll <path>
where
<path>
is the directory containing the executable created
by pyinstaller. This assumes you have installed libusb (using a tool
like Zadig) as referenced in the installation guide for Windows.
“Error: Access denied (insufficient permissions)”
The system may already be using the device.
-
On macOS: starting with 10.9 “Mavericks”, macOS ships with a native FTDI
kernel extension that preempts access to the FTDI device.Up to 10.13 “High Sierra”, this driver can be unloaded this way:
sudo kextunload [-v] -bundle com.apple.driver.AppleUSBFTDI
You may want to use an alias or a tiny script such as
pyftdi/bin/uphy.sh
Please note that the system automatically reloads the driver, so it may be
useful to move the kernel extension so that the system never loads it.Warning
From macOS 10.14 “Mojave”, the Apple kernel extension peacefully
co-exists with libusb and PyFtdi, so you no longer need — and should
not attempt — to unload the kernel extension. If you still experience
this error, please verify you have not installed another driver from FTDI,
such as FTDI’s D2XX. -
On Linux: it may indicate a missing or invalid udev configuration. See
the Installation section. -
This error message may also be triggered whenever the communication port is
already in use.
“Error: The device has no langid”
-
On Linux, it usually comes from the same installation issue as the
Access denied
error: the current user is not granted the permissions to
access the FTDI device, therefore pyusb cannot read the FTDI registers. Check
out the Installation section.
“Bus error / Access violation”
PyFtdi does not use any native library, but relies on PyUSB and libusb. The
latter uses native code that may trigger OS error. Some early development
versions of libusb, for example 1.0.22-b…, have been reported to trigger
such issues. Please ensure you use a stable/final versions of libusb if you
experience this kind of fatal error.
“serial.serialutil.SerialException: Unable to open USB port”
May be caused by a conflict with the FTDI virtual COM port (VCOM). Try
uninstalling the driver. On macOS, refer to this FTDI macOS guide.
Slow initialisation on OS X El Capitan
It may take several seconds to open or enumerate FTDI devices.
If you run libusb <= v1.0.20, be sure to read the Libusb issue on macOS
with OS X 10.11+.