nxt-python error: usb.core.NoBackendError

nxt-python error: usb.core.NoBackendError

我的系统上安装了 Python 2 和 Python 3。

我运行以下脚本:

#!/usr/bin/env python

import nxt.locator
from nxt.motor import *

def spin_around(b):
    m_left = Motor(b, PORT_B)
    m_left.turn(100, 360)
    m_right = Motor(b, PORT_C)
    m_right.turn(-100, 360)

b = nxt.locator.find_one_brick()
spin_around(b)

使用命令:python spin.py,如预期的那样使用 Python 2。

但是,当我 运行 这个命令时,我得到以下错误:

Traceback (most recent call last):
  File "spin.py", line 12, in <module>
    b = nxt.locator.find_one_brick()
  File "/Library/Python/2.7/site-packages/nxt/locator.py", line 112, in find_one_brick
    for s in find_bricks(host, name, silent, method):
  File "/Library/Python/2.7/site-packages/nxt/locator.py", line 43, in find_bricks
    for s in socks:
  File "/Library/Python/2.7/site-packages/nxt/usbsock.py", line 84, in find_bricks
    for bus in usb.busses():
  File "/Library/Python/2.7/site-packages/usb/legacy.py", line 353, in busses
    sorted(core.find(find_all=True), key=lambda d: d.bus),
  File "/Library/Python/2.7/site-packages/usb/core.py", line 1263, in find
    raise NoBackendError('No backend available')
usb.core.NoBackendError: No backend available

当我 运行 这个脚本时,我的 NXT 通过 USB 插入我的电脑并且我的 NXT 是打开的。此外,我已经安装了 pyUSB(我认为是正确的)。

为什么会发生此错误?

解决方案是安装 libUSB。看来 pyUSB 库在后台依赖 libUSB。

我用 brew install libusb

安装了 libUSB

之后,该特定错误得到修复。