Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Writing a super simple LED code, having issues with not being able to import from gpiozero

Im trying to use my raspberry pi electronics kit to run an LED program. My code is just:

from gpiozero import led
from signal import pause

led = LED(4)

led.blink()

pause()

Which throws

Traceback (most recent call last):
  File "/home/pi/python-projects/led.py", line 1, in <module>
    from gpiozero import led
ImportError: cannot import name 'led' from 'gpiozero' (/usr/lib/python3/dist-packages/gpiozero/__init__.py)
>>> 

I have tried reinstalling throught apt with sudo apt-get update && sudo apt-get install python3-gpiozero python-gpiozero but nothing has changed. Im sure its something stupidly simple, I just dont know enough yet to figure it out

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

As per the documentation, it should be LED, not led:

from gpiozero import LED
from time import sleep

led = LED(17)

while True:
    led.on()
    sleep(1)
    led.off()
    sleep(1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading