How to Install the GPIO Python Library

How to Install the GPIO Python Library

If you wish to create a program in Python that utilises the GPIO port on your Raspberry Pi then you'll need to install this library. The RPi.GPIO Python library allows you to easily configure and read-write the input/output pins on the GPIO header within a Python script. There are several GPIO Python libraries available but we recommend you use the one found at http://pypi.python.org/pypi/RPi.GPIO. Although it is possible to download the library through a web browser it's much faster to do the installation process through the terminal on your raspberry pi. At the time of writing the current version of the library is 0.5.3a.

1. Open a terminal window on your raspberry pi and type the following to download the library to your home directory. If a newer version has been released replace the version number with the current version:

wget http://pypi.python.org/packages/source/R/RPi.GPIO/RPi.GPIO-0.5.3a.tar.gz

2. Extract the contents of the downloaded file:

tar xvzf RPi.GPIO-0.5.3a.tar.gz

3. Change to the newly created directory, again remember to change the version number to that of the version you downloaded.

cd RPi.GPIO-0.5.3a

4. Install the library into Python

sudo python setup.py install

5. Remove the directory and its contents

cd

sudo rm -rf RPi.GPIO-0.5.3a/

6. Delete the archive file

rm Rpi.GPIO-0.5.3a.tar.gz

GPIO library is now installed in python, but it won't be loaded by default. To use GPIO library in python start your program with Rpi.GPIO as GPIO at the top. A simple example of programming the GPIO port in Python can be found here.

2 comments

Wayne

Wayne

I have tried doing this on a windows system and it will not install any help for me please

I have tried doing this on a windows system and it will not install any help for me please

Gerard

Gerard

Hi I tried doing the wget in the terminal but it says temporary failure in name resolution. wget: unable to resolve host address ‘pypi.python.org’.

Plz let me know how can I resolve this as soon as possible ty.

Hi I tried doing the wget in the terminal but it says temporary failure in name resolution. wget: unable to resolve host address ‘pypi.python.org’.

Plz let me know how can I resolve this as soon as possible ty.

Leave a comment

All comments are moderated before being published.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.