GPIO Module Error - only runs on raspberry pi
-
RP 4 2GB
Retropie 4.85
Linux 5.10.103 Raspian GNU/Linux 10 (buster)
Official power supplyHi all,
Ever since I upgraded to Pi 4 GPIO doesn't work.Error: This module can only be run on a Raspberry Pi.
Importing the gpio module in interactive python 2 and 3 produces the above error.
python3 >>> import RPi.GPIO as GPIO
I have updated and reinstalled it according to several articles online and there is no fix for my system.
sudo apt-get install python3-rpi.gpio already newest version 0.7.0.0.1
sudo apt install raspi.gpio already newest version (0.20191001) raspi-gpio set to manually installed
So it's a bit of a mess now and power button scripts seem to rely on gpio working. I had this working fine on my previous 3B+.
Any ideas
Thank you -
Can you post the script that produces the error you mentioned ? How did install RetroPie - did you use a clean Pi4 image or did you use your old RPI 3B+ image ?
-
@mitu I used the latest img file from retro pie.
I can give you the script, but it didn't work, so I investigated further by running python3 from the command line as shown above and started testing each line so I could see if there was an error. And the import line produced the error.
Here is the shutdown.py script if you still want it, but I don't think it's relevant because we know which line doesn't work:
#!/usr/bin/python import RPi.GPIO as GPIO import time import subprocess # we will use the pin numbering to match the pins on the Pi, instead of the # GPIO pin outs (makes it easier to keep track of things) GPIO.setmode(GPIO.BOARD) # use the same pin that is used for the reset button (one button to rule them all!) GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_UP) oldButtonState1 = True while True: #grab the current button state buttonState1 = GPIO.input(5) # check to see if button has been pushed if buttonState1 != oldButtonState1 and buttonState1 == False: subprocess.call("shutdown -h now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) oldButtonState1 = buttonState1 time.sleep(.1)
As far as I know, all the scripts import RPi.GPIO so none of them can possibly work if the import statement doesn't work.
The question is why can't I import a library on the pi 4 that was designed specifically for the pi.
-
@lindsay said in GPIO Module Error - only runs on raspberry pi:
I used the latest img file from retro pie.
ok, so it's a new installation.
I can give you the script, but it didn't work, so I investigated further by running python3 from the command line as shown above and started testing each line so I could see if there was an error. And the import line produced the error.
[..]I don't have a Pi4 at hand at this moment, but the
import
command works without issue on a PI3 using a stock (updated) RetroPie image. Regardless, thepython3-rpi.gpio
is provided by the OS (Raspberry Pi OS Lite) and it should work out-of-the-box, without any further installations. RetroPie doesn't add or remove anything related to the GPIO Python module contained in the package.I can try the import statement (and the script) when I have a Pi4 with RetroPie at hand, but I'm not expecting to fail.
-
OK, so I checked on my Pi4 with RetroPie and cannot reproduce the error. The
python3-rpi.gpio
was not installed though on the system, so I installed it and then ran theimport
command without issues.
Running the script also doesn't yield the error you posted (although it complains about A physical pull up resistor is fitted on this channel! on line 17, it doesn't terminate).The Python3 module version installed is (almost) the same:
apt show python3-rpi.gpio Package: python3-rpi.gpio Version: 0.7.0-0.1~bpo10+4 Priority: optional Section: python Source: rpi.gpio Maintainer: Debian Raspberry Pi Maintainers <pkg-raspi-maintainers@lists.alioth.debian.org> Installed-Size: 68.6 kB Depends: rpi.gpio-common (= 0.7.0-0.1~bpo10+4), python3 (<< 3.8), python3 (>= 3.7~), python3:any, libc6 (>= 2.7) Homepage: http://sourceforge.net/projects/raspberry-gpio-python/ Download-Size: 20.7 kB APT-Manual-Installed: yes APT-Sources: http://archive.raspberrypi.org/debian buster/main armhf Packages
Are you sure you haven't manually installed manually some older version of Python (2 or3) module, one that does not supported the Pi4 model ? Try doing an update of the system and the installed OS packages so the latest version of the package is installed.
-
@mitu said in GPIO Module Error - only runs on raspberry pi:
version installed is (almost) the same:
Thank you mitu.
I read that the Pi 4 has pull-up resistors on pins 2 and 3 for IIC protocol. But if this library is specifically for Raspberry Pi, it does make me wonder why it would complain..It may well be the case that I installed something outdated by accident, Python you think? I mean, the version of Python really shouldn't matter as long as it's 2.7 for python 2 and 3.5+ for python 3.
Yeah, I will do a backup and try running updates. Thank you for your help.
-
I am running Python 3.7.3
-
@lindsay said in GPIO Module Error - only runs on raspberry pi:
It may well be the case that I installed something outdated by accident, Python you think? I mean, the version of Python really shouldn't matter as long as it's 2.7 for python 2 and 3.5+ for python 3.
It's a bit more difficult to install Python itself and overwrite the system's installed one, I was thinking you might have installed an older version of the GPIO Python module, which might explain the error message.
Contributions to the project are always appreciated, so if you would like to support us with a donation you can do so here.
Hosting provided by Mythic-Beasts. See the Hosting Information page for more information.