Sol
Sol

Reputation: 51

RPI.GPIO: ModuleNotFoundError: No module named 'RPi.GPIO

Thank you to all the contributors with their posts correlating to **RPI.GPIO**. I have tried most of your suggestions but so far to no avail.

My current version: 0.7.1a4, I'm running bullseye on Pi4 and a python3 programm which should **import the RPi.GPIO as GPIO**. Instead I get: ModuleNotFoundError: No module named 'RPi.GPIO'; 'RPi' is not a package`.

On a bullseye headless the same program imports **RPi.GPIO as GPIO** without a problem.

I have tried various RPi.GPIO installation methods and am receiving as many different messages in return. But nothing so far has solved anything. And now I am without a clue as to where to look or do next.

Method 1:

sudo pip3 install numpy --extra-index-url https://www.piwheels.org/simple

message returned:

Requirement already satisfied: ...dist-packages (1.19.5)

Method 2:

pip install RPi.GPIO

message returned:

Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied

Method 3:

pip3 install RPi.GPIO

message returned:

Requirement already satisfied: ...dist-packages (0.7.1a4)

Method 4:

export CFLAGS=-fcommon
pip3 install RPi.GPIO

message returned:

Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: ...dist-packages (0.7.1a4)

Method 5:

sudo apt-get -y install python3-rpi.gpio

message returned:

...already the newest version (0.7.0-0.2+b1).

Method 6:

sudo apt-get update && sudo apt-get install python-rpi.gpio python3-rpi.gpio

message returned:

python3.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

Method 7:

sudo apt-get install RPi.GPIO

message returned:

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).

Thank you for your suggestions & help

Upvotes: 4

Views: 21639

Answers (3)

pabios
pabios

Reputation: 77

Try this:

import RPi.GPIO as GPIO

Replace RPI.GPIO with RPi.GPIO, the letter i in lowercase, because python is case sensitive

Upvotes: 2

Joramre
Joramre

Reputation: 11

I had the same error. Turns out I had the wrong operating system. I had the 64 bit Bullseye version to mine monero for a short time. But with the normal Bullseye 11 version everything works just fine. You can download it on the raspberry imager.

Upvotes: 0

Pablo Mieres
Pablo Mieres

Reputation: 31

I was with the same error, try all the commands and nothing but now I succeed, I hope it helps you, I just put python3 when reading the code from the console, for example: 'sudo python3 testgpio.py' instead of just python, I hope it serves you

Upvotes: 3

Related Questions