Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
441 views
in Technique[技术] by (71.8m points)

python - PyUSB ValueError: No backend available

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_YangPyUSBNumato.py", line 19, in <module>
    numato = usb.core.find(idVendor=00000006,idProduct = 00000000, backend=backend)
  File "C:Python_Yangusbcore.py", line 1199, in find
    raise ValueError('No backend available')
ValueError: No backend available
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...