dchurch24
Posts: 70
Joined: Thu Dec 06, 2012 7:29 pm

object has no attribute 'setmode'

Sun Feb 24, 2013 3:18 pm

Hi all,

I'm working through this tutorial:

http://www.rpiblog.com/2012/09/using-gp ... k-led.html

...but I keep getting the error:

Code: Select all

sudo python test.py                                Traceback (most recent call last):
  File "test.py", line 11, in <module>
    GPIO.setmode(GPIO.BOARD)
AttributeError: 'module' object has no attribute 'setmode'
I've reinstalled the gpio stuff and I still get this error.

I'm using the latest Wheezy from the RPi site (download about 2 hours ago).

Any ideas as to why I'm getting this?

dchurch24
Posts: 70
Joined: Thu Dec 06, 2012 7:29 pm

Re: object has no attribute 'setmode'

Sun Feb 24, 2013 4:05 pm

Ok, opening the __init.py in the RPi/GPIO folder confirms that 'setmode' doesn't exist.

Is the install broken for the latest Wheezy?

dchurch24
Posts: 70
Joined: Thu Dec 06, 2012 7:29 pm

Re: object has no attribute 'setmode'

Sun Feb 24, 2013 5:25 pm

Bizarre. I reinstalled the SD card, again, and now it works out of the box.

It was the same image that was pushed to the card.

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

Re: object has no attribute 'setmode'

Sun Feb 24, 2013 7:24 pm

try adding "GPIO.setmode(BCM)" or "GPIO.setmode(board)" without quotes towards the top of the code, before setting up the pin's as input/outputs. the pins change depending on the mode, so make sure you have the one you need. I have a short tutorial here:
http://cae2100.wordpress.com/2013/01/10 ... in-python/
If it isnt smoking and blown into pieces, it's not pushed far enough yet. :P
http://cae2100.wordpress.com

User avatar
metachris
Posts: 96
Joined: Wed Feb 06, 2013 1:52 pm
Location: Vienna, Austria

Re: object has no attribute 'setmode'

Sun Feb 24, 2013 8:15 pm

Perhaps you were using an old version of RPi.GPIO. You can update it with `sudo easy_install -U RPi.GPIO`, and print the version with `import RPi.GPIO; print RPi.GPIO.VERSION`.
pythonhosted.org/RPIO

dchurch24
Posts: 70
Joined: Thu Dec 06, 2012 7:29 pm

Re: object has no attribute 'setmode'

Mon Feb 25, 2013 8:07 am

Hi, thanks chaps. I did try (some of) those things before I reinstalled. I updated the RPi.GPIO and it was 1.0.
It's the same version I'm using now.
I must have installed something that buggered it up I guess.
All working now though, thanks guys!

Alveena
Posts: 2
Joined: Sat Oct 17, 2015 6:18 am

Re: object has no attribute 'setmode'

Sat Oct 17, 2015 7:07 am

>>> import RPi.GPIO as GPIO
>>> GPIO.setmod(GPIO.BCM)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'setmod'


help me regarding this

hippy
Posts: 6729
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: object has no attribute 'setmode'

Sat Oct 17, 2015 5:23 pm

Alveena wrote:>>> GPIO.setmod(GPIO.BCM)
Try GPIO.setmode(GPIO.BCM)

Houtkamp
Posts: 8
Joined: Wed Dec 18, 2013 6:50 pm

Re: object has no attribute 'setmode'

Tue Oct 20, 2015 4:32 pm

years and years later, STILL no solution for this...

User avatar
Paeryn
Posts: 2807
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: object has no attribute 'setmode'

Tue Oct 20, 2015 5:00 pm

Houtkamp wrote:years and years later, STILL no solution for this...
No solution to what? The original poster apparently fixed their problem by re-installing the library. Then 2.5 years later somebody else resurrected the thread with a (slightly) different problem - in that it looks like they had typed setmod rather than setmode, and which we have no evidence to say that the given solution (to spell the function name properly) hasn't worked.
She who travels light — forgot something.

Return to “Python”