Wesley Owens
Wesley Owens

Reputation: 21

Pyusb and Libusb giving NoBackendError on MacOS

I'm on MacOS Big Sur trying to run rfcat. I am running anaconda as well and I have set up an environment with Python2.7 when I originally got errors with Python3.x. I have downloaded the pyusb, pyreadline, ipython, PySide2, and the libusb dependancies. Libusb seems to be giving me the most trouble. I keep getting the following error:

Error in resetup():NoBackendError('No backend available',)
Error in resetup():NoBackendError('No backend available',)
Error in resetup():NoBackendError('No backend available',)
^CTraceback (most recent call last):
  File "/opt/anaconda3/envs/rftools/bin/rfcat", line 4, in <module>
    __import__('pkg_resources').run_script('rfcat==1.9.5', 'rfcat')
  File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/pkg_resources/__init__.py", line 666, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1469, in run_script
    exec(script_code, namespace, namespace)
  File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/rfcat-1.9.5-py2.7.egg/EGG-INFO/scripts/rfcat", line 63, in <module>

  File "build/bdist.macosx-10.7-x86_64/egg/rflib/__init__.py", line 208, in interactive
  File "build/bdist.macosx-10.7-x86_64/egg/rflib/chipcon_nic.py", line 103, in __init__
  File "build/bdist.macosx-10.7-x86_64/egg/rflib/chipcon_usb.py", line 93, in __init__
  File "build/bdist.macosx-10.7-x86_64/egg/rflib/chipcon_usb.py", line 238, in resetup
KeyboardInterrupt

From my research so far, backend is how pyusb refers to libusb, libusb1 or openusb. It is unable to find the libusb within the environment. I did a little tracking and found that ultimately, the find_library() function is found in ctypes in util.py. It refers to the executable path for MacOS with @executable_path/../lib/libusb%s..... I tried to put libusb into a folder on my executable path to hopefully match this functions search, and still got the same errors. I then found instructions on inputting a custom path for the backend for pyusb here. This appears to be a method where you input the device and backend information at the beginning of your program. The code I inserted is as follows:

import usb.core
import usb.backend.libusb1 as libusb1

backend = libusb1.get_backend(find_library=lambda x: "/path/to/file/lib/libusb-1.0.0.dylib")
dev = usb.core.find(idVendor=“MyVID”, idProduct=“MyPID”, backend=backend)

This induced a similar error but with a different traceback when I placed the code in rflib.init and the rfcat codes:

Traceback (most recent call last):
  File "/opt/anaconda3/envs/rftools/bin/rfcat", line 4, in <module>
    __import__('pkg_resources').run_script('rfcat==1.9.5', 'rfcat')
  File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/pkg_resources/__init__.py", line 666, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/pkg_resources/__init__.py", line 1469, in run_script
    exec(script_code, namespace, namespace)
  File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/rfcat-1.9.5-py2.7.egg/EGG-INFO/scripts/rfcat", line 12, in <module>

  File "build/bdist.macosx-10.7-x86_64/egg/rflib/__init__.py", line 15, in <module>
  File "/opt/anaconda3/envs/rftools/lib/python2.7/site-packages/usb/core.py", line 1304, in find
    raise NoBackendError('No backend available')
usb.core.NoBackendError: No backend available

I have since reset things back to how I started and am still getting the original error listed above.

I think this largely has to do with the anaconda environment, which I can of course remove. I want to try to find a way to make this work though. Is there a better method to help rfcat find the libusb as required? Another possible solution is resolving the actual executable_path. Does anyone know how to find the executable_path?

In case it helps, I will list the default locations for commands and files.

rfcat: /opt/anaconda3/envs/rftools/lib/python2.7/site-packages/rfcat

pyusb: /opt/anaconda3/envs/rftools/lib/python2.7/site-packages/usb

ctypes: /opt/anaconda3/envs/rftools/lib/python2.7/ctypes

libusb: /opt/anaconda3/envs/rftools/lib/python2.7/site-packages/usb/lib

Upvotes: 2

Views: 745

Answers (0)

Related Questions