3

I'm trying out gpiozero, but after running the examples from their documentation, I still get this errors but it still runs ok.

gpiozero is installed on venv using pip3

#!/usr/bin/env python
from gpiozero import Button
from signal import pause

def say_hello():
    print("Hello!")

button = Button(2)

button.when_pressed = say_hello

pause()
/home/pi/gpiozero/venv/lib/python3.7/site-packages/gpiozero/devices.py:279: PinFactoryFallback: Falling back from rpigpio: No module named 'RPi'                         
  'Falling back from %s: %s' % (name, str(e))))

/home/pi/gpiozero/venv/lib/python3.7/site-packages/gpiozero/devices.py:279: PinFactoryFallback: Falling back from rpio: No module named 'RPIO'                           
  'Falling back from %s: %s' % (name, str(e))))

/home/pi/gpiozero/venv/lib/python3.7/site-packages/gpiozero/devices.py:279: PinFactoryFallback: Falling back from pigpio: No module named 'pigpio'                       
  'Falling back from %s: %s' % (name, str(e))))

If I install RPi.GPIO the error goes away.

5
  • The real question is WHY you felt the need to install gpiozero - it is included in Raspbian. You have probably nobbled it by installing a private copy.
    – Milliways
    Commented Sep 25, 2019 at 11:03
  • GPIOZero is a superset of RPi.GPIO.
    – Dougie
    Commented Sep 25, 2019 at 16:58
  • @Milliways it is not included in Raspbian Lite. I am using venv for my project
    – admin
    Commented Sep 27, 2019 at 15:10
  • 1
    In which case you should install, following the Foundation instructions sudo apt install python3-gpiozero NOT install a private copy
    – Milliways
    Commented Sep 28, 2019 at 2:27
  • @Milliways Your "sudo apt install python3-gpiozero" needs to be an answer, not a comment. It is the correct solution for people (like me) who installed raspian-lite and reach for pip when python packages are needed.
    – Ron Jensen
    Commented Nov 7, 2020 at 17:08

2 Answers 2

3

gpiozero does not need RPi.GPIO. However there is little reason not to install RPi.GPIO, it doesn't take much space and there are a wealth of examples of its usage.

gpiozero can use any one of a number of GPIO library backends to carry out its tasks.

By default it uses RPi.GPIO.

If RPi.GPIO is not installed it defaults to RPIO.GPIO.

If RPIO.GPIO is not installed it defaults to pigpio.

You don't have to exclusively use the default. You can tell gpiozero to use any of the above GPIO libraries (if it's installed) for a specific function.

1

Question

Do I need to install Rpi.GIPIO for GPIO Zero?

Answer

Well, GPIO Zero builds on Rpi.GPIO and other libraries. So if your raspbian does not have it preinstalled, you need to do so.

References

(1) Gpiozero 1.5.1 Documentation > Docs » gpiozero

Pin factories

... GPIO Zero builds on a number of underlying pin libraries, including RPi.GPIO and pigpio, each with their own benefits. You can select a particular pin library to be used, either for the whole script or per-device, according to your needs. See the section on changing the pin factory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.