gpiozero not working

  • Hello, can you help me? I have installed a hardware switch to my RPI to run the shutdown command, I am using gpiozero and it was all working perfectly until I installed the latest LEIA v8.95.1 beta, now if i try to run the command I get an error "ImportError: No module named pkg_resources".

    Here Is the command with the error:

    LibreELEC:~ # python /storage/shutdown-press-simple.py

    Traceback (most recent call last):

    File "/storage/shutdown-press-simple.py", line 5, in <module>

    from gpiozero import Button

    File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/__init__.py", line 22, in <module>

    from .devices import (

    File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/devices.py", line 19, in <module>

    import pkg_resources

    ImportError: No module named pkg_resources

    And in case you need it, this is my script:

    import sys

    sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')

    #!/usr/bin/env python3

    from gpiozero import Button

    import os

    Button(21).wait_for_press()

    os.system("shutdown now")

  • I'm not sure of the reason why it has started failing (Probably a python module is missing), but from the script, you'd be better off using the "official" Raspberry Pi method of shutdown using the dtoverlay as detailed Here

  • Yeah, I think that there's something that needs to be updated by the libreelec gods, hope it gets fixed for the final 9.0 release. Meanwhile I'll try the other method.

  • So, I just wanted to update the issue, I installed the final 9.0 release and the problem seemed to be fixed since I pushed the button and libreelec shutdown successfully but it only worked one time, right after the installation but now gpiozero is not working again.

    Same error message as above.

  • I can confirm.

    Fresh Libreelec install on a Raspi 3B+ with rpi-tools installed.

    The files are in the right place at /storage/.kodi/addons/virtual.rpi-tools/lib

    but the module could not be imported, even after adding the foloowing to the script:

    Code
    import sys
    sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')

    I can currently see no fault or mistake, this "should" work, but it doesn't.

    (Also, gpiozero is now available in version 1.5.0, the module has 1.41. - but this is minor and is unrelated to the above)

  • hi - thanks for your help.

    I finally got around to trying this out.

    It still does not work, this is from the log:

    So the culprit seems to be missing setuptools.

    Any way around this?

    Edited once, last by meinnamehier: typo (February 26, 2019 at 10:00 PM).

  • Seems gpiozero needs setuptools package which is not present on LE.

    Can you try this version with gpiozero 1.5.0? virtual.rpi-tools-9.0.105.rpi2.zip

    Code
    wget -O virtual.rpi-tools-9.0.105.RPi2.zip http://vpeter.libreelec.tv/RPi2/virtual.rpi-tools-9.0.105.RPi2.zip
    unzip virtual.rpi-tools-9.0.105.RPi2.zip -d /storage/.kodi/addons

    Yeah 9.0.105 is the same that already comes with the LE 9.0 repo but I ran the commands anyway, the result is the same, it still doesn't work, same error message from my first post.

    Edit:

    Sorry my bad, I'm still using gpiozero 1.4.1, I'll try to install 1.5.0 and post the result here but right now I have no idea on how to install it on LE

  • Ok, I made it, I installed gpiozero 1.5 but now I get this error:

    LibreELEC:~ # python shutdown-press-simple.py

    Traceback (most recent call last):

    File "shutdown-press-simple.py", line 5, in <module>

    from gpiozero import Button

    File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/__init__.py", line 97, in <module>

    from .output_devices import (

    File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/output_devices.py", line 45, in <module>

    from colorzero import Color

    ImportError: No module named colorzero

  • Under closer inspection, I believe that gpiozero may be badly installed? All I did was to move the gpiozero 1.5.0 folder inside "/storage/.kodi/addons/virtual.rpi-tools/lib", considering that the error seems to be very similar to the one from 1.4.1 may I suggest that gpiozero is not installed as it should in LE 9.0? Or some compatibility issue with python 2?

    Edited once, last by Petes (February 27, 2019 at 3:24 AM).

  • Under lib folder you should have folder gpiozero and colorzero after unpacking my zip file. You should just unpack zip and overwrite old files.

    Code
    unzip virtual.rpi-tools-9.0.105.RPi2.zip -d /storage/.kodi/addons

    I made a mistake with a command before. Sorry.

    Sadly I don't own RPi to actually test it X(

  • The files should be in the right place, if you look at the error messages provided:

    File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/output_devices.py", line 45, in <module>

    or

    File "/storage/.kodi/addons/virtual.rpi-tools/lib/gpiozero/__init__.py"

  • My zip file virtual.rpi-tools-9.0.105.RPi2.zip contains gpiozero 1.5.0 which should not needed setuptools from Python. But it needs colorzero package (which is included in addon).

    Uninstalling addon virtual.rpi-tools and install my version from ZIP should also work. Or just installing. So many options :|

  • My zip file virtual.rpi-tools-9.0.105.RPi2.zip contains gpiozero 1.5.0 which should not needed setuptools from Python. But it needs colorzero package (which is included in addon).

    Uninstalling addon virtual.rpi-tools and install my version from ZIP should also work. Or just installing. So many options :|

    Thank you, I'm no sure what the problem was but it works now!

  • The problem was with old gpiozero version which requires setuptools on LE. And new version can work without. Will send PR so it can be fixed.

    Quote

    This is what you get with bumping packages blindly :( Just because there is newer version it doesn't mean it works the same way as before. And of course no one actually do a test with new version. This was broken for more than 6 months.