24

I downloaded RPi.GPIO 5.3a from here: https://pypi.python.org/pypi/RPi.GPIO

I extracted the tar file, cd into the folder and ran:

sudo python setup.py install

It ran through a bunch of stuff and doesn't seem to have failed. The last line of its work is this:

Writing /usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.5.3a.egg-info

After that it was done and gave me back control.

Now I type

sudo python

then

import RPi.GPIO

and I see

ImportError: No module named GPIO

Can anyone point me to exactly what steps I need to take to get the python GPIO library installed correctly so I can import it and manipulate the GP pins? I've found a mish mash of different processes online (this was the one that came up most often) but I have thus far been unable to get any of them to work.

2

5 Answers 5

33

Not 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
1
  • 1
    E: Package 'python-rpi.gpio' has no installation candidat
    – Kaigo
    Commented May 5, 2022 at 18:59
12

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

6

Another potential cause could be because the RPi.GPIO library has C bindings and therefore need to have python-dev installed in order to compile correctly when installing.

Make sure you've got the python-dev package installed along with the RPi.GPIO package:

sudo apt-get install python-dev python-rpi.gpio

This is the recommended approach on the Adafriuit installation guide:

https://learn.adafruit.com/playing-sounds-and-using-buttons-with-raspberry-pi/install-python-module-rpi-dot-gpio

1

If you are using a fresh image you don’t need to install it.

For the old version

  1. sudo apt-get update
  2. sudo apt-get install rpi.gpio
1

This worked for me on my RPi 4B. Just ensure you have the last version of RPi.GPIO but installed from pip (it was newer) than apt-get:

Remove current RPi.GPIO versions:

sudo apt-get purge python{,3}-rpi.gpio

Update pip first:

sudo -H pip2 install --upgrade pip
sudo -H pip3 install --upgrade pip

Install RPi.GPIO from updated pip:

python -m pip install RPi.GPIO
python3 -m pip install RPi.GPIO
3
  • There is NO NEED to install RPi.GPIO the latest version is included in Raspberry Pi OS and if you need to reinstall use the version in the repository. All you have achieved is resurrecting an obsolete post.
    – Milliways
    Commented Jan 14, 2021 at 11:36
  • 1
    But it might be useful for people that are not running Raspberry Pi OS. In my case, I was running Ubuntu for full ROS compatibility and I needed RPi.GPIO. Commented Jan 16, 2021 at 10:43
  • @JosepClotetGinovart This sollution that you have posted resolved my problem. Thanks to you Bro Commented Nov 1, 2022 at 11:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.