device.detach_kernel_driver(0) - ERROR Could not detach kernel driver: [Errno 13] Access denied (insufficient permissions)
Hello,
I have an issue running the following code, in my cloned github repo.
`from blinkstick import blinkstick
bstick = blinkstick.find_first()
#Set the color red on the 12th LED of R channel bstick.set_color(channel=0, index=12, name="red")`
Specifically it fails in the call at find_first call. here is the full traceback.
Traceback (most recent call last): File "/Users/jmoshiri/Documents/Repos/blinkstick-python/blinkstick/blinkstick.py", line 821, in open_device self.device.detach_kernel_driver(0) File "/Users/jmoshiri/Documents/Repos/blinkstick-python/venv/lib/python3.9/site-packages/usb/core.py", line 1075, in detach_kernel_driver self._ctx.backend.detach_kernel_driver( File "/Users/jmoshiri/Documents/Repos/blinkstick-python/venv/lib/python3.9/site-packages/usb/backend/libusb1.py", line 902, in detach_kernel_driver _check(self.lib.libusb_detach_kernel_driver(dev_handle.handle, intf)) File "/Users/jmoshiri/Documents/Repos/blinkstick-python/venv/lib/python3.9/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)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/jmoshiri/Documents/Repos/blinkstick-python/trial.py", line 4, in
I have given all the correct permissions in the set up for Blinkstick, and also given read write priveleges for all dependencies (usblib and pyusb) . My machine is running Mac OSx Big Sur and I am using Python 3.9.13. The only other way I was thinking to blinkstick via sudo priveleges either from the command line or from the IDE (pycharm in my case).
I got stumped at the command line priveleges in the set up because i do not have a directory udev in /etc for mac OS Big Sur
echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\"20a0\", ATTR{idProduct}==\"41e5\", MODE:=\"0666\"" | sudo tee /etc/udev/rules.d/85-blinkstick.rules
Any help is appreciated.
I've been looking at this on a Mac running Monterey on the arm64 architecture. Apple have a built in Kernel driver which does not need to be detached. I have commented out the call to self.open_device(device) on line 217 and the library still functions correctly. I'm trying to work out how to check if we are running on MacOS before suggesting a change to the library.
I do not advise running anything under sudo privileges, in any case the problem lies in an interaction between libusb and the operating system.
Here is a zip file containing a version which doesn't call open_device() if the platform is "macOS-12.6"