Issue #097 [New/open] - AttributeError: ‘module’ object has no attribute ‘GPIO’

Posted by isalem75

What steps will reproduce the problem?

1- download release 0.7.9 source code 2- perform install through : sudo ./setup.sh 3- run old project that was using version 0.6.2

The upgrade / installation finished successfully .. when I tried to run the project I was working on I got this weird error:

WebIOPi version used? => 0.7.0

Python version used? => 2.7.6

Distro used? (WebIOPi has only been tested on Raspbian Wheezy) => Raspbian Wheezy

Raspberry Pi board revision? (1 or 2) => 1 and 2

For Javascript side bugs, Browser? => No

Please provide any additional information below.

when running the server: sudo webiopi -c /etc/webiopi/config -d

Traceback (most recent call last): File “build/bdist.linux-armv6l/egg/webiopi/__main__.py”, line 75, in main(sys.argv) File “build/bdist.linux-armv6l/egg/webiopi/__main__.py”, line 69, in main server = Server(port=port, configfile=configfile, scriptfile=scriptfile) File “build/bdist.linux-armv6l/egg/webiopi/server/__init__.py”, line 75, in __init__ loader.loadScript(name, source, self.restHandler) File “build/bdist.linux-armv6l/egg/webiopi/utils/loader.py”, line 8, in loadScript script = imp.load_source(name, source) File “/home/pi/webio/python/script.py”, line 7, in GPIO = webiopi.GPIO AttributeError: ‘module’ object has no attribute ‘GPIO’


Comment 1

Posted by andreas.riegg

Module structure has slightly been reorganized from 0.6.2 to 0.7.0 release. For that, 0.6.2 custom Python server scripts don't run eventuelly properly due to module import errors. Please look at the 0.7.0 server script examples and adapt your script (nainly imports) to the changed module structures and then it will run again.


Comment 2

Posted by isalem75

Actually .. I used the exact server script on the site (0.7.0) ..


Comment 3

Posted by andreas.riegg

Are you sure that the compiling of the native C interface module of WebIOPi for the native GPIO ports really succeeded? It looks like that is missing for some reason. Maybe your Distro is missing the gcc or something else went wrong.

Re-run the setup script and watch out for errors when compiling the native C code parts.


Comment 4

Posted by harrybrooke6987

I had this issue and found a fix after hours of installing/unistalling webiopi

cd /usr/local/lib/python3.2/dist-packages/WebIOPi-0.7.0-py3.2-linux-armv61.egg/_webiopi/

In this directory I was missing the file __init__.py if you are missing it too, create it in nano and add the line: __import__("pkg_resources").declare_namespace(__name__)

save and exit and try running your webiopi again.


Comment 5

Posted by harrybrooke6987

note the double underscores, kinda looks like just one to me but they are doubles


Comment 6

Posted by Alex.Szilagyi

I'm still getting this issue, is there any workaround to solve it? I have checked the specified path by Harry and I have the file right in place with the corresponding code but still when trying to import it into my custom python script I'm getting that error.


Comment 7

Posted by Alex.Szilagyi

In the end managed to solve it by reinstall the OS and Webiopi :)


Comment 8

Posted by Christoffer.Holmstedt

I'm experiencing this as well, not sure what is going wrong. Is it possible to force webiopi to use specific python version?


Comment 9

Posted by istvanzk

I'm having the same error (see issue #130).


Comment 10

Posted by alveol85

I have the same problem anyone know how to fix it


Comment 11

Posted by giancapejo

raspberry pi2 same error !!


Comment 12

Posted by hixotan

i had the same error for WebIOPi-0.7.1. this error raised because WebIOPi-0.7.1 need python3 just add --> #!/usr/bin/python3 <-- at your python script.

this my test1.py script :

!/usr/bin/env python3

import webiopi import time

GPIO = webiopi.GPIO

LIGHT = 17

GPIO.setFunction(LIGHT, GPIO.OUT)

GPIO.digitalWrite(LIGHT, GPIO.HIGH) time.sleep(1) GPIO.digitalWrite(LIGHT, GPIO.LOW)

run with --> #python test1.py and python3 test1.py see the different


Comment 13

Posted by Peter.Dikhoff@rocflevoland-ict.nl

sorry adding the python3 as described, does not work /python $ python3 script.py Traceback (most recent call last): File "script.py", line 6, in GPIO = webiopi.GPIO AttributeError: 'module' object has no attribute 'GPIO'


Comment 14

Posted by anup@sparsa.com

Anyone got rid of this issue?? Still getting same error :(


Comment 15

Posted by cbobadilla.dsoft

I tried the test script and i got no error in the first try.

pi@raspberrypi ~/myproject/python $ sudo python test1.py pi@raspberrypi ~/myproject/python $ sudo python3 test1.py Traceback (most recent call last): File "test1.py", line 6, in GPIO = webiopi.GPIO AttributeError: 'module' object has no attribute 'GPIO' pi@raspberrypi ~/myproject/python $


Comment 16

Posted by Peter.Dikhoff@rocflevoland-ict.nl

The sudo added to the command does not make a difference with my installation. I have a fresh image ( updated, upgraded), with only the webiopi installed, the gertboard software does work with python.

where does the webiopi.GPIO come from ? where defined, is there a debug to see which of the libraries are included (I am not that familiar with python)


Comment 17

Posted by ingmar.stapel

I have the same problem with a RaPi 2 and a new installed Wheezy image and WebIoPi. When I start my Python program manually I have no prolbem. I have the problem only if I start the program at start-up via upstart.

Maybe it is a right issue?

Because when I start my python programm manually then I alway start it via sudo python...


Comment 18

Posted by markojgh

I have the same error and I'm going crazy to find the solution. I changed all versions of python, webiopi and the problem continues. Please report if you find solution or this forum. thank you very much


Comment 19

Posted by reidclarke

AttributeError: 'module' object has no attribute 'GPIO'

webiopi on raspberry pi2 this worked for me in stopping the above error...found this fix by luck!

in the webiopi-0.7.1 directory is the python directory, continue below: 1.python/native/cpuinfo.c,change "BCM2708" to "BCM2709"; 2.python/native/gpio.c, change "#define BCM2708_PERI_BASE 0x20000000" to "#define BCM2708_PERI_BASE 0x3f000000"; 3.run setup.sh again.

i hope this helps


Comment 20

Posted by mark.ostkotte

19 worked for me...thank you


Comment 21

Posted by Peter.Dikhoff@rocflevoland-ict.nl

worked for me too, GREAT I did see same changes in de gert-board software but did not know where in the python software to change

there is also an issue with the GPIO numbering, please check Pi documentation. You'll come accros that too.

this is fixed, thanks


Comment 22

Posted by E30Ryan

Post #19 solved the problem for me! Thanks!


Comment 23

Posted by philiptabone

Post #19 works for me too


Comment 24

Posted by jo@raspython.org

Here is a solution: https://www.raspython.org/webiopi-a-simple-but-great-web-api-for-the-raspberry-pi/