EnviroPhat "cannot import name light"


#1

I recently bought a Pi Zero and an Envirophat. I’ve soldered on the headers (first time soldering something this small) and connected the two. As far as I can tell all pins have a good connection, but you may decide: picture of soldering. After that I’ve made an SD card with NOOBS and installed Raspbian. Then I followed the guide to install the required software. After that I tried some of the example scripts to test everything. That’s when the problems started. The first time two scripts worked perfectly, but the third (temperature logging) wouldn’t work. My own script, made by following the tutorial, also doesn’t work. The error message I get is

Traceback (most recent call last):
File “envirophat.py”, line 4, in <\module>
from envirophat import light, motion, weather, leds
File “/home/pi/Pimoroni/envirophat/examples/envirophat.py”, line 4, in <\module>
from envirophat import light, motion, weather, leds
ImportError: cannot import name light

My code is exactly the same as the tutorial, with the addition of #!/usr/bin/env python at the beginning.

What could be the issue and how can I fix it?


#2

The problem is that you named your file ‘envirophat.py’… when you ask thereafter one of the example to ‘import envirophat’ or ‘from envirophat import’, it will look into this file and will not be able to find the classes you specified for import.

… I hope I’m being clear, but if not check out the following link that goes into more details:

http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-name-shadowing-trap