Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

ImportError after Pip update to v0.8.0 #19

Closed
Jaharmi opened this issue Jun 22, 2020 · 9 comments
Closed

ImportError after Pip update to v0.8.0 #19

Jaharmi opened this issue Jun 22, 2020 · 9 comments
Assignees

Comments

@Jaharmi
Copy link

Jaharmi commented Jun 22, 2020

I updated my virtualenv that includes blynclight to v0.8.0 using Pip. Afterwards, I get an import error both in ptpython and the same thing when using the CLI tool.

>>> from blynclight import BlyncLight                                           
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "$HOME/python-virtual-environments/rgb_led_status/lib/python3.8/site-packages/blynclight/__init__.py", line 34, in <module>
    from .blynclight import BlyncLight
  File "$HOME/python-virtual-environments/rgb_led_status/lib/python3.8/site-packages/blynclight/blynclight.py", line 4, in <module>
    import hid
  File "$HOME/python-virtual-environments/rgb_led_status/lib/python3.8/site-packages/hid/__init__.py", line 30, in <module>
    raise ImportError(error)
ImportError: Unable to load any of the following libraries:libhidapi-hidraw.so libhidapi-hidraw.so.0 libhidapi-libusb.so libhidapi-libusb.so.0 libhidapi-iohidmanager.so libhidapi-iohidmanager.so.0 libhidapi.dylib hidapi.dll libhidapi-0.dll

I'm looking into what's going on.

My update went from:

  • blynclight-0.5.1 to blynclight-0.8.0
  • not sure if hidapi was installed to hidapi-0.9.0.post3
@JnyJny
Copy link
Owner

JnyJny commented Jun 22, 2020

So this is a replay of the previous issue (#17) but now the players are hidapi and Cython rather than my buggy HID wrapper and ctypes. Cython uses a hybrid language that's a combination of Python and C to wrap shared objects and I will have to do some research to find out how it locates shared libraries. The early workaround from #17 (copying files from /opt/local/lib to /usr/local/lib) will likely work in this case too. After research below this is not true.

I'll update as soon as I have a better idea of how Cython works.

@JnyJny JnyJny self-assigned this Jun 23, 2020
@JnyJny
Copy link
Owner

JnyJny commented Jun 23, 2020

I did some reading (docs and code) and have improved my understanding of Cython projects and packaging. It appears that cython-hidapi does not need a separate shared object installed to function. I tested this by removing hidapi and installing blycnlight in a virtual environment:

$ brew uninstall hidapi   # sudo port uninstall hidapi should work too
$ mkdir tmp; cd tmp
$ python3 -n venv venv 
$ source venv/bin/activate
$ pip install blynclight
...
$ blync # light turns on green

To be honest this is a tidier solution than my previous implementation, so I really hope we can get this working for you.

@JnyJny
Copy link
Owner

JnyJny commented Jun 23, 2020

I'm curious what the output of pip list in that virtual environment with the busted blynclight installed.

In the venv created above, I got this output:

$ pip list
Package    Version
---------- -----------
blynclight 0.8.0
certifi    2020.6.20
chardet    3.0.4
click      7.1.2
hidapi     0.9.0.post3
idna       2.9
pip        20.1.1
requests   2.24.0
setuptools 47.3.1
typer      0.2.1
urllib3    1.25.9

@JnyJny
Copy link
Owner

JnyJny commented Jun 23, 2020

Embarrassingly, the 0.8.0 release was built from a feature branch (hid) and not master which may or may not have been completely up-to-date. I've reconciled the two branches and pushed a new release 0.8.2 to PyPI.

@Jaharmi
Copy link
Author

Jaharmi commented Jun 23, 2020

I got both the blynclight and luxafaret modules — or at least their CLI tools — to work with the following new venv. I installed only the two "busy light" modules and their requirements, along with updating pip. It looks like Pip installed the new release v0.8.2.

$ pip list
Package    Version
---------- -------------
blynclight 0.8.2
certifi    2020.6.20
chardet    3.0.4
click      7.1.2
hidapi     0.7.99.post21
idna       2.9
luxafaret  1.1.0
pip        20.1.1
requests   2.24.0
setuptools 41.2.0
typer      0.2.1
urllib3    1.25.9
webcolors  1.11.1

There is a conflict between the two "busy light" modules I'm currently using when it comes to hidapi but both appear to work fine with the older version required by luxafaret.

ERROR: blynclight 0.8.2 has requirement hidapi<0.10.0,>=0.9.0, but you'll have hidapi 0.7.99.post21 which is incompatible.

I made no other changes to the compiled libraries installed in my /usr/local/lib and /opt/local/lib directories.

Meanwhile, my errors were in a different venv that contained the following modules. I'd been experimenting with different modules to control my two RGB LED busy lights.

$ pip list
Package        Version
-------------- -------------
appdirs        1.4.4
blynclight     0.8.0
certifi        2020.4.5.2
chardet        3.0.4
click          7.1.2
Flask          1.1.2
Flask-HTTPAuth 4.1.0
gevent         20.6.2
greenlet       0.4.16
hid            1.0.4
hidapi         0.7.99.post21
idna           2.9
itsdangerous   1.1.0
jedi           0.17.0
Jinja2         2.11.2
luxafaret      1.1.0
MarkupSafe     1.1.1
parso          0.7.0
pip            20.1.1
prompt-toolkit 3.0.5
ptpython       3.0.2
Pygments       2.6.1
pyluxa4        1.6
requests       2.23.0
setuptools     41.2.0
typer          0.2.1
urllib3        1.25.9
wcwidth        0.2.4
webcolors      1.11.1
Werkzeug       1.0.1
wheel          0.34.2
zope.event     4.4
zope.interface 5.1.0

@JnyJny
Copy link
Owner

JnyJny commented Jun 23, 2020

I think I see a problem in the pip list output: there is a hid and hidapi listed and they both likely provide a 'hid' namespace. I'll have to check, but my gut says that blynclight was expecting to get hidapi's namespace and got the other (which blew up for unrelated reasons. I spent a lot of time trying to figure out where that error message was either in my code or in the trezor/cython-hidapi code).

I can relax the version requirements for hidapi in the packaging for blynclight to see if that helps improve your situation.

@JnyJny
Copy link
Owner

JnyJny commented Jun 23, 2020

Yep, I've recreated the error that started this issue. I don't have libhidapi.dyld installed by either ports or brew:

$ pip list
Package    Version
---------- ---------
certifi    2020.6.20
chardet    3.0.4
click      7.1.2
hid        1.0.4
idna       2.9
pip        20.1.1
requests   2.24.0
setuptools 47.3.1
typer      0.2.1
urllib3    1.25.9

$ python3 -c "import hid"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/ejo/tmp/venv/.venv/lib/python3.7/site-packages/hid/__init__.py", line 30, in <module>
    raise ImportError(error)
ImportError: Unable to load any of the following libraries:libhidapi-hidraw.so libhidapi-hidraw.so.0 libhidapi-libusb.so libhidapi-libusb.so.0 libhidapi-iohidmanager.so libhidapi-iohidmanager.so.0 libhidapi.dylib hidapi.dll libhidapi-0.dll

It is my opinion that the Cython hidapi solution is superior by nearly every measure I can think of:

  • tracks libhidapi closely
  • pip install builds a shared object directly used by python
  • does not require the user to install hidapi via [brew|port|apt-get|yum|rpm|whatever]
  • actively developed (by not me)

If you like, I can take a look at the luxafaret code to see about porting to Cython hidapi ( should be trivial ).

@JnyJny
Copy link
Owner

JnyJny commented Jun 24, 2020

So I took a look at the Luxafaret project and it seems a little abandoned. I've ordered a LuxaFor flag and it should be here Thursday :) I'll add support to blynclight for the Flag and that will solve having to get our two projects synced enough to not interfere with each other.

@JnyJny
Copy link
Owner

JnyJny commented Jul 13, 2020

@Jaharmi I've got a new project you might be interested in, busylight-for-humans. It supports both Embrava BlyncLights and Luxafor Flags from the same command-line:

$ busylight list
...
$ busylight supported
Embrava BlyncLight
Luxafor Flag
$ busylight on
$ busylight blink
$ busylight off

This should help you work with your lights while not having to fight dependencies. Let me know how it works for you.

@JnyJny JnyJny closed this as completed Jul 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants