0

So I'm trying to use pyusb in a conda environment but it fails with error below:

>>> import usb.core
>>> usb.core.find()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/foo/Developer/anaconda3/envs/delme/lib/python3.6/site-packages/usb/core.py", line 1263, in find
    raise NoBackendError('No backend available')

I'm assuming this happens because it can't find libusb. I have tried installing libusb and libusb1 inside the conda environment via pip and also system-wide (libusb and libusb-compat) via brew but none of these have helped.

Milad
  • 4,901
  • 5
  • 32
  • 43
  • How does pyusb try to find the backend? – darthbith Sep 25 '17 at 18:45
  • It seems to be using `ctypes.util.find_library` – Milad Sep 25 '17 at 19:07
  • [this question](https://stackoverflow.com/questions/31148387/which-paths-does-python-ctypes-module-search-for-libraries-on-mac-os) helped. If I manually add `/usr/local/lib` to `DYLD_LIBRARY_PATH` env variable find_library can see libusb but one would think that it should be there already. – Milad Sep 25 '17 at 19:21
  • I figured out what's going on. For reasons that I don't rememberI had added some paths to DYLD_FALLBACK_LIBRARY_PATH when I was trying to compile something. According to dyld's manual the default value for DYLD_FALLBACK_LIBRARY_PATH is $(HOME)/lib:/usr/local/lib:/lib:/usr/lib which covers where libusb is but looks like by extending DYLD_FALLBACK_LIBRARY_PATH it's lost those default values. – Milad Sep 26 '17 at 14:52
  • Awesome! Glad you figured it out! You can post an answer here to close this up. – darthbith Sep 26 '17 at 14:58

1 Answers1

0

I figured out what's happening so I might as well answer my own question – someone else might find it useful.

For reasons that I don't remember anymore I had added some paths to DYLD_FALLBACK_LIBRARY_PATH when I was trying to compile something. According to dyld's manual the default value for DYLD_FALLBACK_LIBRARY_PATH is $(HOME)/lib:/usr/local/lib:/lib:/usr/lib which covers where libusb is but looks like by extending DYLD_FALLBACK_LIBRARY_PATH it's lost those default values.

So if you have similar issues you might want to take a look at these variables.

Milad
  • 4,901
  • 5
  • 32
  • 43