custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
874 stars 46 forks source link

Allow all imports appears to have stopped working with the latest HA update? #536

Closed aredon closed 10 months ago

aredon commented 11 months ago

I have a simple script that imports lifxlan in order to do some fancier things with zone lights. It was working just fine all week until I updated HA and now the log is spitting the following:

line 3: import lifxlan ^ ModuleNotFoundError: No module named 'lifxlan'

I will just go ahead and use requirements.txt in the future but thought this should be flagged regardless.

craigbarratt commented 11 months ago

Is there something about the update of HA that caused installed modules to no longer be available? This doesn't seem like a pyscript issue (unless there is a breaking change in the latest HA version). If your code imports a module, then you need to make sure it's installed.

ALERTua commented 11 months ago

I cannot confirm this issue. You should investigate the module installation logs. The module installs fine on my Python 3.11.6 @ Windows 11 virtualenv. Try double-checking whether the module presents in requirements.txt, and requirements.txt is placed where it belongs.

aredon commented 11 months ago

I actually didn't have it in requirements.txt at all before and it was working (I had assumed through allow all imports?). It loads up fine when added to requirements.txt - maybe I'm mistaken in my understanding of allow-all-imports. If that's the case you can close this out.

Unfortunately/regardless the module is now broken but that isn't really your issue.

ALERTua commented 11 months ago

If you were able to import a module, this means that it was installed by something as a prerequisite. You were just lucky that the module was there. Luckily, pyscript allows the installation of PyPi modules via requirements.txt. Glad you resolved your issue.

aredon commented 11 months ago

Ahh! Well that explains it then. I'll poke around and see if I can load an old version of bitstring and get lifxlan working again. Thanks for prompt replies.

aredon commented 11 months ago

Any thoughts on why adding bitstring==3.1.9 doesn't seem to be loading the old version? The documentation says it won't load an old one if a new one already exists in HA but when I do pip show bitstring in an HA console it says that it isn't installed.

alexwhittemore commented 11 months ago

Is it possible your module import issue is related to the same root cause that's stopping fresh installation on the latest version of home assitant? https://github.com/custom-components/pyscript/issues/524

It seems to me like perhaps there was some breaking change upstream that produces weird results if your installation is was already configured.

aredon commented 11 months ago

Is it possible your module import issue is related to the same root cause that's stopping fresh installation on the latest version of home assitant? #524

It seems to me like perhaps there was some breaking change upstream that produces weird results if your installation is was already configured.

Probably not? This seems like it was just me not knowing what I was doing.