juanma_cab
Posts: 19
Joined: Fri Mar 26, 2021 3:56 pm

RPI.GPIO error " RuntimeError: Not running on a RPi!"

Mon Apr 19, 2021 12:20 pm

Hi! I'm using Ubuntu 20.10 on Raspberry Pi 4 4GB, but using RPi.GPIO library on my code Terminal shows to me this message:

"GPIO.setup(INT, GPIO.IN, pull_up_down=GPIO.PUD_UP)
RuntimeError: Not running on a RPi!"

This is the code:

Code: Select all

#!/usr/bin/env python2.7
import RPi.GPIO as GPIO
import subprocess
from time import sleep

GPIO.setmode(GPIO.BCM) # use GPIO numbering
GPIO.setwarnings(False)
print('RPi.GPIO:',GPIO.VERSION)

INT = 12    # GPIO-12 button interrupt to shutdown procedure

# use a weak pull_up to create a high
GPIO.setup(INT, GPIO.IN, pull_up_down=GPIO.PUD_UP)

def main():

     while True:
      # set an interrupt on a falling edge and wait for it to happen
      GPIO.wait_for_edge(INT, GPIO.FALLING)
      # we got here because the button was pressed.
      # wait for 3 seconds to see if this was deliberate
      sleep(3)
      # check the button level again
      if GPIO.input(INT) == 0:
      # still pressed, it must be a serious request; shutdown Pi
          subprocess.call(['poweroff'], shell=True, \
          stdout=subprocess.PIPE, stderr=subprocess.PIPE)


if __name__ == '__main__':
      main()
I can't found the mistake of the code, Is there any problem between Ubuntu and this library?

Thank you so much!

waw
Posts: 2
Joined: Mon Apr 19, 2021 12:54 pm
Location: Desktop

Re: RPI.GPIO error " RuntimeError: Not running on a RPi!"

Mon Apr 19, 2021 12:56 pm

It should work on newest RPi.GPIO https://pypi.org/project/RPi.GPIO/0.7.1a4/

User avatar
DougieLawson
Posts: 41185
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: RPI.GPIO error " RuntimeError: Not running on a RPi!"

Mon Apr 19, 2021 3:40 pm

1. Don't use python2
2. You version of RPi.GPIO is backlevel and doesn't have the hardware support for a RPi4B
3. Post your question on the Ubuntu forums as they need to fix RPi.GPIO in their distro.

https://askubuntu.com/questions/1290037 ... xit-status
Any language using left-hand whitespace for syntax is ridiculous

Any DMs sent on Twitter will be answered next month.
Fake doctors - are all on my foes list.

Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Return to “Ubuntu”