dannyprior30
Posts: 8
Joined: Sun Jul 17, 2016 10:10 pm

python import help

Sun Nov 06, 2016 5:53 pm

Hello

using gpiozero and i'm getting the following error

ImportError: cannot import name Servo

code is below. i copied this from the gpiozero website. any ideas?

from gpiozero import Servo
from time import sleep

servo = Servo(7)
while True:
servo.min()
sleep(1)
servo.mid()
sleep(1)
servo.max()
sleep(1)

scotty101
Posts: 3958
Joined: Fri Jun 08, 2012 6:03 pm

Re: python import help

Sun Nov 06, 2016 5:56 pm

Do any of the gpiozero modules work. Try

Code: Select all

from gpiozero import LED
Electronic and Computer Engineer
Pi Interests: Home Automation, IOT, Python and Tkinter

dannyprior30
Posts: 8
Joined: Sun Jul 17, 2016 10:10 pm

Re: python import help

Sun Nov 06, 2016 6:18 pm

Yes that works. no errors

dannyprior30
Posts: 8
Joined: Sun Jul 17, 2016 10:10 pm

Re: python import help

Sun Nov 06, 2016 6:23 pm

just did dir(gpiozero). looks like Servo is not a function that can be called.

i'm installing from the latest copy

sudo apt-get install python3-gpiozero python-gpiozero
Reading package lists... Done
Building dependency tree
Reading state information... Done
python-gpiozero is already the newest version.
python3-gpiozero is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 49 not upgraded.

User avatar
B.Goode
Posts: 10356
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: python import help

Sun Nov 06, 2016 6:34 pm

Are you sure it is version 1.3 that you are importing?

http://gpiozero.readthedocs.io/en/lates ... -installed

dannyprior30
Posts: 8
Joined: Sun Jul 17, 2016 10:10 pm

Re: python import help

Tue Nov 08, 2016 9:08 pm

B.Goode, looks like i'm on version 1.2. i run the update script and it says i'm on the latest version. any ideas? :?

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

Re: python import help

Wed Nov 09, 2016 6:56 pm

What's your script called? If it's gpiozero.py that will cause this problem, renaming it will sort it out.

Dave.
Apple say... Monkey do !!

dannyprior30
Posts: 8
Joined: Sun Jul 17, 2016 10:10 pm

Re: python import help

Wed Nov 09, 2016 8:18 pm

Hello all

Turns out i wasn't installing the right version. i will using the install from the gpiozero site but you should use the below install

"sudo pip install gpiozero" and "sudo pip3 install gpiozero"

Thanks everyone for your help

Danny

Return to “Python”