5

I am runing Python 2.7.8 at Win 7 operation system. I am trying to communicate a USB device (Numato 32 channel GPIO device) by PyUSB.

I downloaded walac-pyusb-7071ad3 from URL: http://walac.github.io/pyusb

I stop at receiving "ValueError: No backend available". Could any Python expert tell me where is wrong?

Here is the code:

import sys
import usb
import usb.core
import usb.util
import usb.backend.libusb1

backend = usb.backend.libusb1.get_backend(find_library=lambda C:'\Python27')
numato = usb.core.find(idVendor=00000006,idProduct = 00000000, backend=backend)

Here is Python error message:

Traceback (most recent call last):
  File "C:\Python_Yang\PyUSBNumato.py", line 19, in <module>
    numato = usb.core.find(idVendor=00000006,idProduct = 00000000, backend=backend)
  File "C:\Python_Yang\usb\core.py", line 1199, in find
    raise ValueError('No backend available')
ValueError: No backend available
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Joyful CD
  • 51
  • 1
  • 1
  • 4
  • 3
    Possible duplicate of [Pyusb on windows - no backend available](http://stackoverflow.com/questions/13773132/pyusb-on-windows-no-backend-available) – endolith Jan 12 '16 at 15:01

3 Answers3

2

I had the same error, but I didn't succeed to use find_library(TypeError: get_backend() got an unexpected keyword argument 'find_library'). I suppose, although you did not say it, that backend is not valid (None).

Do you have the libusb1 implementation in the path C:\Python27 ? I suppose you didn't install it in the Python's folder and if so, there's your answer: PyUSB backend not accessible.

Otherwise, without using find_library, you must have the libusb1 implementation available in the PATH environment variable. I did it like this (you can replace os.getcwd() with your location):

def get_backend_libusb01():
    libusb01_location = os.getcwd()

    # load-library (ctypes.util.find_library) workaround: also search the current folder
    is_current_folder_in_search_path = True
    if None == usb.backend.libusb0.get_backend():
        is_current_folder_in_search_path = libusb01_location in os.environ['PATH']
        if not is_current_folder_in_search_path:
            os.environ['PATH'] += os.pathsep + libusb01_location

    backend = usb.backend.libusb0.get_backend()

    if not is_current_folder_in_search_path:
        os.environ['PATH'] = os.environ['PATH'].replace(os.pathsep + libusb01_location, "")

    return backend
Community
  • 1
  • 1
Liviu
  • 1,859
  • 2
  • 22
  • 48
  • Here are some updates: Eventually, I found that the USB device is not a true USB device, but a RS-232 Emulation device. Now the problem is solved by using pyserial for communication. – Joyful CD Sep 16 '14 at 04:33
  • Related question: http://stackoverflow.com/questions/13773132/pyusb-on-windows-no-backend-available/ – Liviu Sep 16 '14 at 12:54
  • Sorry to hijack comments, but I'm having some issues running your function because ```usb.backend.libusb01``` isn't defined: ```dir(usb.backend) ['IBackend', '__all__', '__author__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '_not_implemented', '_objfinalizer']```. I've installed pyusb 1.0 from walac's repo and I had libusb-1.0 already installed. Am I missing anything ? – George Profenza Feb 25 '15 at 14:24
  • `libusb01` was renamed to `libusb0` in the latest version of `PyUSB`, also notice that `libusb0` stands for `libusb-0.1` and `libusb1` for `libusb-1.0` (http://www.libusb.org/). Also, be careful that "libusb-win32 is a port of the USB library libusb-0.1" even if the version is 1.2.6. I changed the code to reflect the changes, thank you! – Liviu Feb 26 '15 at 09:54
  • Merci frumos Liviu. I noticed libusb0 was defined but libusb01 was not but it's confusing to which submodule leads to what. Thanks for explaining this. – George Profenza Feb 26 '15 at 11:45
  • @Liviu it seems that i have run into the same problem as Joyful CD. but the difference is that i have downloaded and unzipped the file(libusb1.0.20),then copied a dll file, specifically(libusb-1.0.dll) and copied it to system 32; then i copied libusb-1.lib to python34/Lib. and still there is 'no backend' error,so can you help me solve the problem? – Socre Nov 04 '16 at 16:02
1

I had this trouble, and i switched python libusb wrappers and its gone: https://github.com/vpelletier/python-libusb1

Hayden Thring
  • 1,718
  • 17
  • 25
1

I did: - Download and install libusb-win32-devel-filter-1.2.6.0.exe. It should work.

From:

Pyusb on windows - no backend available

And really works for me.

Wellington1993
  • 340
  • 1
  • 3
  • 17