aidanmack
Posts: 22
Joined: Thu Jun 14, 2012 11:00 am

rpi.gpio error 'module' object has no attribute 'setmode'

Thu Jun 20, 2013 4:00 pm

Hi all,
Im trying to use RPI.GPIO

...But not gettting very far at all

This is my code...

Code: Select all

try:
    import RPi.GPIO as GPIO
except RuntimeError:
    print("Error")

print(str(GPIO))
GPIO.setmode(GPIO.BOARD)

my print returns...
<module 'RPi.GPIO' from '/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/GPIO/__init__.pyc'>


and the error I get is....


File "rpigiotest.py", line 11, in <module>
GPIO.setmode(GPIO.BOARD)



Anyone any ideas where I could be going wrong..

samson241
Posts: 81
Joined: Fri Apr 05, 2013 7:07 am
Location: Western United States

Re: rpi.gpio error 'module' object has no attribute 'setmod

Thu Jun 20, 2013 6:08 pm

possibly setMode? been a long time sice I used this. :?
I realize this question must seem stupid and i apologize in advance.

cae2100
Posts: 143
Joined: Tue Jan 08, 2013 10:35 am
Contact: Website

Re: rpi.gpio error 'module' object has no attribute 'setmod

Thu Jun 20, 2013 7:48 pm

first, try to do "sudo apt-get update && sudo apt-get upgrade" to get rid of the chance that it's just an old version, and here's a short tutorial on the GPIO pins and python:

http://cae2100.wordpress.com/2013/01/10 ... in-python/

hope that helps.
If it isnt smoking and blown into pieces, it's not pushed far enough yet. :P
http://cae2100.wordpress.com

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: rpi.gpio error 'module' object has no attribute 'setmod

Thu Jun 20, 2013 8:16 pm

Could you post your code in full? The error is apparently in line 11 but you don't seem to have that many lines.

Dave.
Apple say... Monkey do !!

User avatar
croston
Posts: 716
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: rpi.gpio error 'module' object has no attribute 'setmod

Thu Jun 20, 2013 9:21 pm

You have a really ancient version of RPi.GPIO - before setmode() was added. I suggest you upgrade it. As you have manually installed it, you will have to manually delete it to pick up the latest version from Raspbian.

aidanmack
Posts: 22
Joined: Thu Jun 14, 2012 11:00 am

Re: rpi.gpio error 'module' object has no attribute 'setmod

Fri Jun 21, 2013 9:14 am

Sweet! manual delete and reinstall worked!


impressive that you spotted it was an old version mate! good work.

Cheers fellas.

Jaws84
Posts: 1
Joined: Mon Jul 15, 2013 5:28 pm

Re: rpi.gpio error 'module' object has no attribute 'setmod

Mon Jul 15, 2013 5:34 pm

I have the exact same problem with my rpi.gpio package.
How exactly did you solve it?

sudo apt-get --purge remove python3-rpi.gpio python-rpi.gpio
sudo apt-get install python3-rpi.gpio python-rpi.gpio

didn't work for me.

jesusbarazartem
Posts: 2
Joined: Fri Sep 12, 2014 8:09 pm

Re: rpi.gpio error 'module' object has no attribute 'setmod

Fri Sep 12, 2014 8:38 pm

Hi guys, i have a similar problem with it.

this is the error:

Traceback (most recent call last):
File "Blink.py", line 4, in <module>
GPIO.setmode(GPIO.BMC)
AttributeError: 'module' object has no attribute 'BMC'

And this is my code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BMC)
GPIO.setup(18,GPIO.OUT)

while True:
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
GPIO.output(18,GPIO.LOW)
time.sleep(1)

i did before
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo apt-get install python-rpi.gpio python3-rpi.gpio
But it doesn't work yet

What this error means? what i should do?
somebody help me

eternalfame
Posts: 7
Joined: Sun Sep 07, 2014 10:57 am

Re: rpi.gpio error 'module' object has no attribute 'setmod

Sat Sep 13, 2014 6:08 am

jesusbarazartem wrote:Hi guys, i have a similar problem with it.

this is the error:

Traceback (most recent call last):
File "Blink.py", line 4, in <module>
GPIO.setmode(GPIO.BMC)
AttributeError: 'module' object has no attribute 'BMC'

And this is my code:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BMC)
GPIO.setup(18,GPIO.OUT)

while True:
GPIO.output(18,GPIO.HIGH)
time.sleep(1)
GPIO.output(18,GPIO.LOW)
time.sleep(1)

i did before
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ sudo apt-get install python-rpi.gpio python3-rpi.gpio
But it doesn't work yet

What this error means? what i should do?
somebody help me

It's BCM not BMC

jesusbarazartem
Posts: 2
Joined: Fri Sep 12, 2014 8:09 pm

Re: rpi.gpio error 'module' object has no attribute 'setmod

Mon Sep 15, 2014 3:18 pm

Thanks eternalfame wow i didn't see before... thinks that can happen !!

chgus
Posts: 19
Joined: Thu Feb 26, 2015 12:34 pm
Location: Sweden

Re: rpi.gpio error 'module' object has no attribute 'setmod

Thu Feb 26, 2015 1:19 pm

Hi,
i guess i'm on to the cause of this problem.

One upon a time I installed a 0.1.0 version GPIO on my very first Pi board. Since then RPi.GPIO has become part of the distribution and is installed by apt-get install command. Got the instructions from a web page after some google check. It might have been installed using easy_install, but i'm not shure.

I am now stuck with two versions, 0.1.0 and 0.5.7 at the same time ...

Code: Select all

chgus@raspberrypi:~$ find /usr | grep -i gip
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/__init__.pyc
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/__init__.py
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/GPIO
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/GPIO/__init__.pyc
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/RPi/GPIO/__init__.py
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/top_level.txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/PKG-INFO
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/SOURCES.txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/dependency_links.txt
/usr/local/lib/python2.7/dist-packages/RPi.GPIO-0.1.0-py2.7.egg/EGG-INFO/zip-safe
/usr/local/lib/python3.2/dist-packages/RPi.GPIO-0.5.7.egg-info
/usr/local/lib/python3.2/dist-packages/RPi.GPIO-0.5.7.egg-info/top_level.txt
/usr/local/lib/python3.2/dist-packages/RPi.GPIO-0.5.7.egg-info/PKG-INFO
/usr/local/lib/python3.2/dist-packages/RPi.GPIO-0.5.7.egg-info/installed-files.txt
/usr/local/lib/python3.2/dist-packages/RPi.GPIO-0.5.7.egg-info/SOURCES.txt
/usr/local/lib/python3.2/dist-packages/RPi.GPIO-0.5.7.egg-info/dependency_links.txt
/usr/local/lib/python3.2/dist-packages/RPi/GPIO.cpython-32mu.so
While i was prepairing this post i found out that it was even worse: I have three versions installed, 0.1.0, 0.5.7 and 0.5.11. 0.5.11 installs with apt-get install python-dpi.gpio and get updated as new releases become available.

My solution was to 'easy_install' away the ancient 0.1.0 by
sudo easy_install -m RPi.GPIO-0.1.0

Even though there still is a 0.5.7 version lurking around, the version reported both by pydoc and .VESRION is now 0.5.11

Code: Select all

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
>>> RPi.GPIO.VERSION
'0.5.11'
>>> 

Jeff7beck
Posts: 1
Joined: Mon May 18, 2015 1:51 am

Re: rpi.gpio error 'module' object has no attribute 'setmod

Mon May 18, 2015 2:20 am

hey guys i keep getting this error code am not sure what the problem is, can anyone help please.

Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1437, in __call__
return self.func(*args)
File "/home/pi/robotics/robot2.pi", line 64, in key_input
init()
File "/home/pi/robotics/robot2.pi", line 9, in init
gpio.setup(7, gpio.out)
AttributeError: 'module' object has no attribute 'out'

here is a copy of my code


import RPi.GPIO as gpio
import time
import sys
import Tkinter as tk

def init():

gpio.setmode(gpio.BOARD)
gpio.setup(7, gpio.out)
gpio.setup(11, gpio.OUT)
gpio.setup(13, gpio.OUT)
gpio.setup(15, gpio.OUT)

def forward(tf):
gpio.output(7, False)
gpio.output(11, True)
gpio.output(13, True)
gpio.output(15, False)
time.sleep(tf)
gpio.cleanup()

def reverse(tf):
gpio.output(7, True)
gpio.output(11, False)
gpio.output(13, False)
gpio.output(15, True)
time.sleep(tf)
gpio.cleanup()

def turn_left():
gpio.output(7, True)
gpio.output(11, True)
gpio.output(13, True)
gpio.output(15, False)
time.sleep(tf)
gpio.cleanup()

def turn_right():
gpio.output(7, False)
gpio.output(11, True)
gpio.output(13, False)
gpio.output(15, False)
time.sleep(tf)
gpio.cleanup()

def pivot_left(tf):
gpio.output(7, True)
gpio.output(11, False)
gpio.output(13, True)
gpio.output(15, False)
time.sleep(tf)
gpio.cleanup()

def pivot_right(tf):
gpio.output(7, False)
gpio.output(11, True)
gpio.output(13, False)
gpio.output(15, True)
time.sleep(tf)
gpio.cleanup()


def key_input(event):
init()
print'Key:', event.char
key_press = event.char
sleep_time = .040

if key_press.lower() == 'w':
forward(sleep_time)
elif key_press.lower() == 's':
reverse(sleep_time)
elif key_press.lower() == 'a':
turn_left(sleep_time)
elif key_press.lower() == 'd':
turn_right(sleep_time)
elif key_press.lower() == 'q':
pivot_left(sleep_time)
elif key_press.lower() == 'e':
pivot_right(sleep_time)
else:
pass
command = tk.Tk()
command.bind('<KeyPress>', key_input)
command.mainloop()

User avatar
DougieLawson
Posts: 40134
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: rpi.gpio error 'module' object has no attribute 'setmod

Mon May 18, 2015 7:52 am

When you post code on the forum please use [code]...[/code] tags as that makes your programs easier to read and it keeps the formatting (which is a syntax requirement for python).

Code: Select all

#!/usr/bin/python
import RPi.GPIO as gpio

gpio_Pin_buzz = 8

gpio.setmode(gpio.BCM)
gpio.setwarnings(False)

gpio.setup(gpio_Pin_buzz, gpio.OUT)
gpio.output(gpio_Pin_buzz, gpio.LOW)
Python is case sensitive so GPIO.OUT is not the same as GPIO.out or gpio.out or gpio.OUT.
Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Return to “Python”