0

When running code

import RPi.GPIO as GPIO
import MFRC522
import signal

continue_reading = True

# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
    global continue_reading
    print "Ctrl+C captured, ending read."
    continue_reading = False
    GPIO.cleanup()
...

I get the error

Traceback (most recent call last): File "Read.py", line 1, in import RPi.GPIO as GPIO ImportError: No module named RPi.GPIO

I've checked out many answers on stackexchange about this but cannot get the solutions to work.

I've tried,

pip install RPi.GPIO

Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (0.7.0)

sudo apt install RPi.GPIO

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'python3-rpi.gpio' for regex 'RPi.GPIO'
Note, selecting 'python-rpi.gpio' for regex 'RPi.GPIO'
Note, selecting 'rpi.gpio-common' for regex 'RPi.GPIO'
python3-rpi.gpio is already the newest version (0.7.0-0.2+b1).
rpi.gpio-common is already the newest version (0.7.0-0.2+b1).
rpi.gpio-common set to manually installed.
The following package was automatically installed and is no longer required:
  libfuse2
Use 'sudo apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 22 not upgraded.

sudo apt install python-rpi.gpio

sudo apt-get -y install python-rpi.gpio
Hit:1 http://raspbian.raspberrypi.org/raspbian bullseye InRelease
Hit:2 http://archive.raspberrypi.org/debian bullseye InRelease
Reading package lists... Done             
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package python-rpi.gpio is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'python-rpi.gpio' has no installation candidate

I'm using python 2.7.18 on latest rasbian image.

I'm following this guide here for using an RFID reader

9
  • Python 2.X is no longer supported. You have a version of RPi.GPIO installed which supports Python3. May 5 at 19:31
  • There is no need to do anything. RPi.GPIO is included in the image. I suggest you start again to remove all the mess you have installed (preferably a fresh install) AND DO NOT install obsolete python 2.
    – Milliways
    May 5 at 23:00
  • To make matters worse the packages installed by pip are not for Bullseye.
    – Milliways
    May 5 at 23:04
  • But when I try python3 I get errors about the print(" and print " mismatch. I'd have to change hundreds of lines in the library files too.
    – Kaigo
    May 6 at 20:41
  • 1
    Take a look at 2to3: stackoverflow.com/a/20458067/7467472
    – Sim Son
    May 6 at 22:49

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.