Working on getting some working samples setup for my son on his RPI4 so he can play with the GPIO's, breadboard, and some various pieces to use with the breadboard. Right now we're trying to test out a RGB LED, and are using the gpiozero library in python3

Note that I did not install the gpiozero library, I was just playing with some code samples I found online to get it up and running for him quickly and realized the library came packaged with the PI OS already. However, now I'm confused as to why it thinks it's not running on a RPI? Looking at the docs it appears that gpiozero should run on all Pi's, but it has zero in the name, is this only compatible with a Pi zero?

This is what I'm running. Note that this is a snippet of the full script, I reduced it to 2 lines to reproduce the error, but the error below lists it as line 10 from the file(10 = 2 in my sample below)

from gpiozero import RGBLED
led = RGBLED(red=18, green=23, blue=24)

And getting this error

Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 109, in pin
    pin = self.pins[n]
KeyError: 18

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "04_cheerlights.py", line 10, in <module>
    led = RGBLED(red=18, green=23, blue=24)
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 124, 
in __call__
    self = super(GPIOMeta, cls).__call__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", 
line 901, in __init__
    for pin in (red, green, blue)
  File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", 
line 901, in <genexpr>
    for pin in (red, green, blue)
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 124, 
in __call__
    self = super(GPIOMeta, cls).__call__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", 
line 414, in __init__
    pin, active_high, initial_value=None, pin_factory=pin_factory
  File "/usr/lib/python3/dist-packages/gpiozero/output_devices.py", 
line 93, in __init__
    super(OutputDevice, self).__init__(pin, pin_factory=pin_factory)
  File "/usr/lib/python3/dist-packages/gpiozero/mixins.py", line 106, 
in __init__
    super(SourceMixin, self).__init__(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/gpiozero/devices.py", line 521, 
in __init__
    pin = self.pin_factory.pin(pin)
  File "/usr/lib/python3/dist-packages/gpiozero/pins/pi.py", line 111, 
in pin
    pin = self.pin_class(self, n)
  File "/usr/lib/python3/dist-packages/gpiozero/pins/rpigpio.py", line 
132, in __init__
     GPIO.setup(self.number, GPIO.IN, self.GPIO_PULL_UPS[self._pull])
RuntimeError: Not running on a RPi!

Also, here's my OS version info

cat /etc/os-release 
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION="10 (buster)"


uname -a
Linux *hostname* 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux
  • 1
    the 2 lines of code that generate the error are included in the post. What else are you looking for? Sep 16, 2020 at 6:21
  • 1
    As an experiment try using a different backend
    – joan
    Sep 16, 2020 at 6:22
  • 1
    yeah, I get that they do nothing, however on my system they generate the error I am trying to fix, which makes the rest of the code irrelevant. Sep 16, 2020 at 6:30
  • 1
    Joan, when you say use a different backend, what are you referring to by "backend"? Sep 16, 2020 at 6:32
  • 2
    Is your OS fully updated? ‘sudo apt update‘ ‘sudo apt full-upgrade -y’ I suspect RPi.GPIO is out of date.
    – CoderMike
    Sep 16, 2020 at 8:57

1 Answer 1


Don't run as a limited user. Need to run the script as root or the default Pi account and all is right with the world again.

  • Ah, out of habit newbie me never run bash python but always jail breaking Thonny.
    – tlfong01
    Sep 16, 2020 at 15:27
  • Or add your limited user to the "gpio" group which, on Raspbian at least, permits access to the GPIO registers
    – Dave Jones
    Sep 17, 2020 at 9:32
  • Please mark the answer as the accepted one with a click on the tick on its left side. That prevents your Question from being shown as a unsolved Post to the community and saves them/us a lot of work.
    – Ingo
    Sep 18, 2020 at 15:24

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.