3

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

I ran the next code:

sudo python setup.py install

there are no fails on the installing.

I will run the next script:

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

I see now the next:

ImportError: No module named GPIO

when I have done the following:

sudo apt-get update
sudo apt-get -y install python-rpi.gpio

The importerror does not go away.

I use the raspberry pi 2 with raspbian

4
  • Did you call your script RPi.py? Or do you have a dir called RPi in the crurent dir? If yes, change it's name.
    – salmon
    Feb 7, 2015 at 21:50
  • I did my script call RPi.py and it's not working.
    – Hessel
    Feb 8, 2015 at 8:36
  • Jest rename your file. You called it RPi.py. python uses it as a module and tries to import GPIO from it.
    – salmon
    Feb 8, 2015 at 9:16
  • Not finding the modules still sounds to me that the modules are not in the right path according to the python version used. I guess raspian comes with python2 and python3. Which one is used for running the script? Against which (which pip) is used to install the modules?
    – Ghanima
    Apr 9, 2015 at 19:57

4 Answers 4

1

The Pi libraries are in a state of flux because of the changes required to work on the Pi 2.

Either wait for a while for a stable version to be available from the Raspbian repositories or install a development version according to the instructions at http://sourceforge.net/p/raspberry-gpio-python/wiki/install/

Summary

To install the latest development version from the project source code library:

$ sudo apt-get install python-dev python3-dev
$ sudo apt-get install mercurial
$ sudo apt-get install python-pip python3-pip
$ sudo apt-get remove python-rpi.gpio python3-rpi.gpio
$ sudo pip install hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO
$ sudo pip-3.2 install hg+http://hg.code.sf.net/p/raspberry-gpio-python/code#egg=RPi.GPIO

To revert back to the default version in Raspbian:

$ sudo pip uninstall RPi.GPIO
$ sudo pip-3.2 uninstall RPi.GPIO
$ sudo apt-get install python-rpi.gpio python3-rpi.gpio
1
  • it does not work for me? what am I doing wrong? I followed all the steps ..
    – Hessel
    Feb 7, 2015 at 20:57
1

I have a fresh NOOBS 1.4.1 Raspbian install and I'm able to import without a problem:

pi@mediapi ~ $ python
Python 2.7.3 (default, Mar 18 2014, 05:13:23)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import RPi.GPIO as GPIO
>>> GPIO
<module 'RPi.GPIO' from '/usr/lib/python2.7/dist-packages/RPi/GPIO.so'>
0

Update, Upgrade, Re-install and do all the things necessary.

Then try the command 'import RPi.GPIO'.

(Remember - R and P are in higher case in RPi, and GPIO has all higher case letters.)

Worked for me in python 2.7.13

-2

Use sudo python3 filename.py, this worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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