JnyJny / blynclight

Python bindings for the Embrava BlyncLight family of products.
Apache License 2.0
21 stars 3 forks source link

MacOSX - usb.core.NoBackendError: No backend available when calling BlyncLight.available_lights() #5

Closed bkcrisler closed 5 years ago

bkcrisler commented 5 years ago

`>>> from blynclight import BlyncLight

BlyncLight.available_lights() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.7/site-packages/blynclight/blynclight.py", line 96, in available_lights return [cls(d) for d in usb.core.find(idVendor=vendor_id, find_all=True)] File "/usr/local/lib/python3.7/site-packages/usb/core.py", line 1263, in find raise NoBackendError('No backend available') usb.core.NoBackendError: No backend available light = BlyncLight.first_light() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.7/site-packages/blynclight/blynclight.py", line 112, in first_light return cls(usb.core.find(idVendor=vendor_id)) File "/usr/local/lib/python3.7/site-packages/usb/core.py", line 1263, in find raise NoBackendError('No backend available') usb.core.NoBackendError: No backend available`

Issue is resolved by: brew install libusb since they PyUSB won't work properly without libusb

JnyJny commented 5 years ago

Dang that's the same problem as the libhidapi solution that I jettisoned for PyUSB. Thank you for report and resolution. I'll update the README with Linux and macOS best practices for install libusb and then think about how to automate getting it installed.

bkcrisler commented 5 years ago

Seems like there also a problem with the permissions. Its more to do with libusb:

`

from blynclight import BlyncLight light = BlyncLight.first_light() red, blue, green = (255, 0, 0), (0, 255, 0), (0, 0, 255) light.color = green Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.7/site-packages/blynclight/blynclight.py", line 190, in setattr super().setattr(name, value) File "/usr/local/lib/python3.7/site-packages/blynclight/blynclight.py", line 312, in color self.update_device() File "/usr/local/lib/python3.7/site-packages/blynclight/blynclight.py", line 386, in update_device self._timeout) File "/usr/local/lib/python3.7/site-packages/usb/core.py", line 1034, in ctrl_transfer self._ctx.managed_claim_interface(self, interface_number) File "/usr/local/lib/python3.7/site-packages/usb/core.py", line 102, in wrapper return f(self, *args, **kwargs) File "/usr/local/lib/python3.7/site-packages/usb/core.py", line 167, in managed_claim_interface self.backend.claim_interface(self.handle, i) File "/usr/local/lib/python3.7/site-packages/usb/backend/libusb1.py", line 811, in claim_interface _check(self.lib.libusb_claim_interface(dev_handle.handle, intf)) File "/usr/local/lib/python3.7/site-packages/usb/backend/libusb1.py", line 595, in _check raise USBError(_strerror(ret), ret, _libusb_errno[ret]) usb.core.USBError: [Errno 13] Access denied (insufficient permissions)

This is raised on a different thread here:

https://github.com/braiden/python-ant-downloader/issues/30

JnyJny commented 5 years ago

Thanks, that is definitely a permission problem. Can you post the output of the terminal command "groups"? Maybe I can see what group you need to be in to access the light.

neilernst commented 5 years ago

I have the same issue, here is my groups output:

staff com.apple.sharepoint.group.1 everyone localaccounts _appserverusr admin _appserveradm _lpadmin 
com.apple.access_screensharing access_bpf com.apple.sharepoint.group.2 _appstore _lpoperator _developer _analyticsusers com.apple.access_ftp com.apple.access_ssh
JnyJny commented 5 years ago

Just a quick note that I'm working on this but have nothing to show for it yet.

Out of curiosity, what level macOS are you using? I started running into this problem when I updated to Mojave and haven't had time to debug it sufficiently.

neilernst commented 5 years ago

This is Python 3.6.4, pyusb 1.0.2, Mac 10.14.4

JnyJny commented 5 years ago

So it looks like I'll need to go back to hidapi since pyusb has no plans to make this work on macOS. To be fair, it's not a PyUSB problem, it's an "Apple not playing well with open source" problem (AFAICT).

JnyJny commented 5 years ago

I've just pushed changes to how USB devices are accessed by the blynclight module. For macOS, Linux and Windows you'll need to install the hidapi library. The easiest way to do that for macOS is using brew:

$ brew install hidapi

I've tested specifically with version 0.8.0-rc1 of hidapi.

Give it a try and let me know what trouble you run into.

JnyJny commented 5 years ago

Closing this issue as solved... for now.

neilernst commented 5 years ago

this update worked ... thanks a lot!

JnyJny commented 5 years ago

Great news! Thank you for the feedback, that means a lot to me.

wyojustin commented 3 years ago

Thanks for all your hard work @JnyJny . I seem to be having the same error

bash-3.2$ python antfs_list.py Driver available: [<class 'ant.base.driver.SerialDriver'>, <class 'ant.base.driver.USB2Driver'>, <class 'ant.base.driver.USB3Driver'>] Aborted Stop Traceback (most recent call last): File "antfs_list.py", line 93, in <module> main() File "antfs_list.py", line 81, in main a = Listener() File "antfs_list.py", line 36, in __init__ Application.__init__(self) File "/Users/justin/anaconda3/lib/python3.6/site-packages/ant/fs/manager.py", line 107, in __init__ self._node = Node() File "/Users/justin/anaconda3/lib/python3.6/site-packages/ant/easy/node.py", line 55, in __init__ self.ant = Ant() File "/Users/justin/anaconda3/lib/python3.6/site-packages/ant/base/ant.py", line 46, in __init__ self._driver = find_driver() File "/Users/justin/anaconda3/lib/python3.6/site-packages/ant/base/driver.py", line 272, in find_driver if driver.find(): File "/Users/justin/anaconda3/lib/python3.6/site-packages/ant/base/driver.py", line 159, in find usb.core.find(idVendor=cls.ID_VENDOR, idProduct=cls.ID_PRODUCT) File "/Users/justin/anaconda3/lib/python3.6/site-packages/usb/core.py", line 1297, in find raise NoBackendError('No backend available') usb.core.NoBackendError: No backend available bash-3.2$

I tried $ brew install hidapi to no avail. Any suggestions? macOS Mojave 10.14.4 macbook pro 2017

JnyJny commented 3 years ago

Whoa. First off it appears that antfs_list.py uses PyUSB which is a different method of accessing USB devices than used by HID API, so installing hidapi probably (for sure) isn't going to solve this problem. I develop on a Mac and around the Mojave timeframe I started having trouble with PyUSB and I switched to HID API to communicate with USB devices. I did some searching and I'm guessing that this is from the openant project; I didn't see any issues for MacOS there. A casual inspection of the code seems to indicate the author is mostly developing for a Linux environment, so might not be aware of MacOS related problems with USB devices.

Take a look at the PyUSB FAQ and see if this helps

wyojustin commented 3 years ago

Thanks for the quick feedback... will do.

Justin