You may install it with pip :
pip install RPi.GPIO
Answer from Timothée on Stack OverflowNot sure if this is helpful, but under the latest copy of Raspbian I was able to install RPi.GPIO directly from the main repositories using apt-get as follows:
sudo apt-get update
sudo apt-get -y install python-rpi.gpio
If you're running Python 3 (idle3 on the command line) instead of Python 2 (python on the command line) you need to install the RPi.GPIO library with this command instead:
sudo apt-get -y install python3-rpi.gpio
Assuming you have pip, the python package index installer, which is installed on the latest versions of Raspbian by default
You can use:
sudo pip install RPi.GPIO for Python 2
and
sudo pip-3.2 install RPi.GPIO for Python 3
python - Installing RPi.GPIO on Ubuntu Core - Raspberry Pi Stack Exchange
raspbian - RPi.GPIO under Python 3 - Raspberry Pi Stack Exchange
raspberry pi3 - RPi.GPIO Not Found in Python 3 - Stack Overflow
How to install python3-lgpio on Ubuntu 20.04 on a Raspberry Pi - Stack Overflow
I was able to fix the issue by installing RPi.gpio using pip3. Type the following commands:
export CFLAGS=-fcommon
pip3 install RPi.GPIO
Source: https://www.raspberrypi.org/forums/viewtopic.php?t=289084
As of version 20.10, Ubuntu does not come with Python 2 installed as it is deprecated. It does have python 3. You use python3 to run python and pip3 to install modules.
this is reprint of an answer by karel at this location https://askubuntu.com/questions/621134/gpio-on-raspberry-pi
In the terminal type:
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install python-pip python-dev
sudo pip install RPi.GPIO
The raspberry-gpio-python examples are worth reading. In the Inputs example there is this code snippet:
while GPIO.input(channel) == GPIO.LOW:
time.sleep(0.01)
It waits 10 ms to give CPU a chance to do other things.
It is because your environment variable LC_ALL is missing or invalid somehow. just run
$ export LC_ALL=C
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM) # set board mode to Broadcom
GPIO.setup(17, GPIO.OUT) # set up pin 17
GPIO.setup(18, GPIO.OUT) # set up pin 18
GPIO.output(17, 1) # turn on pin 17
GPIO.output(18, 1) # turn on pin 18
from here.
It might be that your Pi is not updated.
Go to the command line on your pi and enter:
sudo apt-get update
sudo apt-get upgrade
After running these commands, reinstall both the packages. It should work.