Pyusb on windows - no backend available - python
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.
Download and install libusb-win32-devel-filter-1.2.6.0.exe. It should work.
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.
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.
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.
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
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()
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\
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.
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).
"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.
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...
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.
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)
Related
MetaTrader5 libarary in Python 3.7
I am trying to analyze currency data using MT5 in Python but it is not working. I didn't understand where is the problem? even importing is not work from MetaTrader5 import * from datetime import date # Initializing MT5 connection MT5Initialize() MT5WaitForTerminal() print(MT5TerminalInfo()) print(MT5Version()) This is the error: MT5WaitForTerminal()RuntimeError: No IPC connection
I had the same issue and I found the following solution: My terminal was downloaded from the broker site and probably had some modifications that block ipc connections. I downloaded original software from https://www.metatrader5.com/en/download and copied "Config" folder from broker's version. Now python script works.
I have a computer with a Windows 10 64-bit installation where everything would work without a hitch. I also have another machine with a Windows 10 32-bit installation, which would always complain about an invalid IPC connection. Not the official MetaTrader 5 version, nor my broker's customized version would work out of the box. I eventually fixed it by specifying the path to my broker's exe in the initialize function like below (check for your own path, and mind the use of / instead of \): mt5.initialize("C:/Program Files (x86)/GT247/terminal.exe")
Usage of rpy2 with a custom installation of R
Dear fellow programmers, I would like to use R inside of a ipython notebook. On the system (Centos) I am working on exists an older version of R (2.15). I was able to execute R-code with this version in a ipython notebook, however, I need a newer version of R with extra packages and because I don't have administrative right for that machine, I have a local machine on which I installed the newest version of R (3.1.2). I compiled the source on my pc and flagged it in a way that it can be assessed by extensions. After that I installed rpy2 with pip and this installation went without any errors. I also can import the rpy2 package, but when I try to load libraries, I get an error message: Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/my/homedir/Software/R-3.1.2/library/stats/libs/stats.so': libRlapack.so: cannot open shared object file: No such file or directory During startup - Warning message: package \u2018stats\u2019 in options("defaultPackages") was not found I looked it up, all libraries are present and I don't get an error when I use R without ipython. Anyone has ideas? Best, Daniel
Have you tried this? http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2 It's very weird when you say you need admin right to update R version because R usually doesn't require admin right to be installed. Make sure you install that under your user folder, instead of somewhere in the system drive.
cx_Oracle: ImportError: DLL load failed: This application has failed
Here's what I did: I'm on Windows XP SP3 I already had Python 2.7.1 installed. I downloaded instantclient-basic-nt-11.2.0.3.0.zip, unzipped it, and put it in C:\Program Files\Oracle\instantclient_11_2. I added this path to the Windows Path environment variable. I created a new environment variable ORACLE_HOME holding this path as its value. I installed cx_Oracle-5.1.2-11g.win32-py2.7.msi. And on running import cx_Oracle all I get is Traceback (most recent call last): File "<string>", line 2, in <module> ImportError: DLL load failed: This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem. I obviously uninstalled / reinstalled cx_Oracle a couple of times but really nothing seems to help. Could anyone please provide a clue how to fix this? UPDATE I ran Dependency Walker and it comes up with a lot of trouble. However, the first missing .dll (msvcr80.dll) is actually present in C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.91_x-ww_0de56c07.
OK, what finally solved the problem (not sure whether all steps are necessary and no idea why exactly this and only this worked so far): Download and unzip version 12 from here. Add "ORACLE_HOME" as a Windows environment variable and set its value to ...\instantclient_12_1, (not its containing folder!). Add this same path to the "Path" environment variable. Only now install cx_Oracle.
To help other people with the same problem: This error tells about 32-64 bit mismatch between some DLL while importing module. Possibilities are: Different architecture of Python and cx_Oracle (less probable since cx_Oracle installer on Windows warns you if appropriate Python was not found). Different architecture of cx_Oracle libraries and oci.dll (more probable). Keep in mind that cx_Oracle uses standart Oracle client (at OCI level), which must be installed on your machine. It searches for oci.dll in several places, including PATH. If it finds oci.dll of wrong version of the client, the error appears. In case you get this error, check path list in the PATH environment variable. It is likely to contain path to BIN folder of wrong version of Oracle client. If you have several clients, specify in the PATH the appropriate one, or install the appropriate client. NOTE: ORACLE_HOME does not have an effect for cx_Oracle. In my case only changing of PATH helped. I think the Ruben's solution works because of item 3 ('Add this same path to the "Path" environment variable').
I am using python35 64 bit and oracle express on win 7 (64 bit). I installed cx_Oracle using pip3 (pip3 install cx_Oracle) instead of downloading the installer from pypi. I faced the same problem. I solved it by following above guidelines, but instead of 32 bit client, I downloaded the 64 bit version of the instant client (instantclient-basic-windows.x64-11.2.0.4.0.zip) from http://www.oracle.com/technetwork/topics/winx64soft-089540.html. I then extracted it to c:\oraclexe. And added these environment variables set ORACLE_BASE=C:\oraclexe set ORACLE_HOME=C:\oraclexe\app\oracle\product\11.2.0\server set PATH=C:\oraclexe\instantclient_11_2;%PATH% And ran my django migrate commands: python manage.py migrate It worked excellent
Easy way: Make sure you have installed cx-Oracle, I have cx_Oracle-5.1.3-11g.win32-py2.7.exe Download, unzip instantclient_12_1 and move it to C:\Python27 Add environment variable C:\Python27\instantclient_12_1 Restart your computer
Same ImportError occured for setup of: Windows 10 x64 Oracle Instant Client 12_1 x64 Python 2.7.11 x64 cx_Oracle cx_Oracle-5.2-12c.win-amd64-py2.7 I solved it copying msvcr100.dll file into <oracle_instant_client_dir>
Had this issue also, and it seems importing cx_Oracle (at least as of 5.1.2) will fail (with the same error) if you have any invalid/unreachable UNC paths in front of Oracle in the PATH environment variable. Fixing the UNC path (which was unrelated to Oracle) resolved the problem.
If you're using conda as a package manager, one way to overcome the DLL issue it to install oracle-instantclient by doing a conda install oracle-instantclient. This fixed the dependency which I couldn't fix by manually installing Oracle's instant-client.
As is the second time I came to this question, I feel the need to post what I did: I'm using: Win 8 64 bits Python 2.7 I had no success installing Python and cx_Oracle 64 bits. It only worked when I tried 32 bits versions and followed #rob answer instructions
I had same issue with DLL load failed on my Windows machine. installed oracle client, set variables, ran cx_Oracle-5.1.3-11g.win32-py2.7.exe file. however when I installed cx_Oracle with easy_setup it fixed the problem. C:\Python27\Scripts\easy_install.exe cx_Oracle-5.1.3-11g.win32-py2.7.exe
Steps I have followed : Downloaded the smart client instantclient-basic-windows.x64-12.1.0.2.0.zip Extracted and copied to #your directory#\instantclient_12_1 Above directory contains dll's Append the PATH variable with #your directory#\instantclient_12_1 and created env variable ORACLE_HOME= #your directory#\instantclient_12_1 Download and install cx_Oracle-5.2.1-11g.win-amd64-py2.7.exe Open idle type import cx_Oracle
if you're using Anaconda on Windows try: conda install cx_oracle on your cmd -> this
I know this is an old post, but I had this problem today and none of the solutions worked. I figure this could work for others with the same problem as of now. Python version : 2.7.15 (64 bits) cx_Oracle version : 6.4.1 Oracle Instant Client : 18.3 I kept getting the following error even though I followed evry steps in the correct order : cx_Oracle.DatabaseError: DPI-1047: Oracle Client library cannot be loaded I solved it by downgrading my Oracle Instant Client version to 12.1
libusb installed- but pyUSB backend not found
I am trying to design a GUI using wxGlade for a USB device. The pyUSB portion of the code has been added to the python code generated by Glade. However, there is an error. 'No backend available' This is is response to using a function usbDev = usb.core.find(idVendor = 0xfffe, idProduct = 0x0001) I have already installed libusb-win32 and still it doesn't work. I restarted the PC once, but to no avail. Kindly help.
I had the same problem too. Then, I tried ActivePython2.7.x.x Link->http://www.activestate.com/activepython/downloads Download the 2.7.x.x 32-bit version. The 64-bit version doesn't allow the installation of pyusb! Then install pyusb and proceed. Works fine.
Installing python with python win32 extensions on a network drive
I need to keep a large number of Windows XP machines running the same version of python, with an assortment of modules, one of which is python-win32. I thought about installing python on a network drive that is mounted by all the client machines, and just adjust the path on the clients. Python starts up fine from the network, but when importing win32com I get a pop-up error saying: The procedure entry point ?PyWinObject_AsHANDLE##YAHPAU_object##PAPAXH#Z could not be located in the dynamic link library pywintypes24.dll after dismissing the message dialog I get in the console: ImportError: DLL load failed: The specified procedure could not be found. I searched the python directory for the pywintypes24.dll and it is present in "Lib\site-packages\pywin32_system32" . What am I missing and is there another way in which I can install Python + Python-Win32 + additional module once and have them running on many machines? I don't have access to the Microsoft systems management tools, so I need to be a bit more low-tech than that.
On every machine you have to basically run following pywin32_postinstall.py -install once. Assuming your python installation on the network is N:\Python26, run following command on every client: N:\Python26\python.exe N:\Python26\Scripts\pywin32_postinstall.py -install Another important thing is Good Luck!. The reason is that you might need to do this as admin. In my case such setup worked for all but one computer. I still did not figure out why.
Python (or precisely, the OS) searches the DLLs using os.environ["PATH"] and not by searching sys.path. So you could start Python using a simple .cmd file instead which adds \server\share\python26 to the path (given the installer (or you) copied the DLLs from \server\share\python26\lib\site-packages\pywin32-system32 to \server\share\python26). Or, you can add the following code to your scripts before they try to import win32api etc: # Add Python installation directory to the path, # because on Windows 7 the pywin32 installer fails to copy # the required DLLs to the %WINDIR%\System32 directory and # copies them to the Python installation directory instead. # Fortunately, in Python it is possible to modify the PATH # before loading the DLLs. os.environ["PATH"] = sys.prefix + ";" + os.environ.get("PATH") import win32gui import win32con
You could use batch files running at boot to Mount the network share (net use \\server\share) Copy the Python and packages installers from the network share to a local folder Check version of the msi installer against the installed version If different, uninstall Python and all version dependent packages Reinstall all packages This would be pretty much a roll your own central management system for that software.