Piglow - Error Messages

Folks, many moons ago I have programmed in Basic and Assembler but Python is new to me and I am stumbling over your instructions to get the piglow working.

Installing the library and copying the examples in this repository to ~/Pimoroni/piglow no problem.

First stumbling block; import piglow - you don’t mention but I assume you have to enter python to issue this command, I then follow with piglow.red(64) and get the following error;

piglow.red(64)
Traceback (most recent call last):
File “”, line 1, in
AttributeError: ‘module’ object has no attribute ‘red’

If I try and run an example, eg python legs.py

Get this error;

Traceback (most recent call last):
File “legs.py”, line 11, in
piglow.leg((x % 3), 64)
AttributeError: ‘module’ object has no attribute ‘leg’
pi@raspberrypi ~/Pimoroni/piglow $

I am using a Pi 2 - no idea what to do next.

Geffers

Strangely, I’ve subsequently found out that the examples in the subdirectory boeeerb DO work but only if run as sudo whereas the examples in the piglow directory don’t run.

Geffers

This sounds like you’ve got the wrong PiGlow library installed- there are 3 or 4, some of which conflict for the “piglow” name and make a bit of a mess. Our fault for not having a proper library out on day one- but those were early days!

You should first remove all old PiGlow libraries like so:

sudo pip uninstall piglow

And then install our library:

sudo pip install piglow

And hopefully that will solve your woes!

Did that and no joy.

Ran python bar.py and get the following;

pi@raspberrypi ~/Pimoroni/piglow $ sudo python bar.py
Traceback (most recent call last):
File “bar.py”, line 8, in
piglow.leg_bar(0, x / 100.0)
AttributeError: ‘module’ object has no attribute ‘leg_bar’

If I run from within python I get;

bar.py
Traceback (most recent call last):
File “”, line 1, in
NameError: name ‘bar’ is not defined

The boeeerb files work but ONLY if I run sudo python

In the piglow directory piglow.py is not executable, is that correct? And no idea what piglow.pyc is.

-rwxr-xr-x 1 pi pi 486 Nov 24 20:50 bar.py
drwxr-xr-x 2 pi pi 4096 Nov 24 20:50 boeeerb
-rwxr-xr-x 1 pi pi 213 Nov 24 20:50 cycle.py
-rwxr-xr-x 1 pi pi 263 Nov 24 20:50 legs.py
-rw-r–r-- 1 pi pi 9846 Nov 24 21:00 piglow.py
-rw-r–r-- 1 pi pi 10238 Nov 24 21:01 piglow.pyc

Geoff

Looking at your folder structure, it would appear as though your local copy of piglow.py is interfering with the library.

When it imports Piglow, Python will first look in the current folder and load the piglow.py file instead of the library. The piglow.pyc file is a “compiled” version of this library which Python generates automatically to speed things up.

If piglow.py is a script which you’ve written, you should rename it to something else so it doesn’t conflict.

Folks, obviously I have a problem here, I did not intentionally create the piglow.py file as I don’t understand the content.

Anyway, renamed it, still didn’t work, rebooted Pi, output as follows;

pi@raspberrypi ~/Pimoroni/piglow ls -l total 40 -rwxr-xr-x 1 pi pi 486 Nov 24 20:50 bar.py drwxr-xr-x 2 pi pi 4096 Nov 24 20:50 boeeerb -rwxr-xr-x 1 pi pi 213 Nov 24 20:50 cycle.py -rwxr-xr-x 1 pi pi 263 Nov 24 20:50 legs.py -rw-r--r-- 1 pi pi 9846 Nov 24 21:00 piglowORIG.py -rw-r--r-- 1 pi pi 10238 Nov 24 21:01 piglow.pyc pi@raspberrypi ~/Pimoroni/piglow bar.py
-bash: bar.py: command not found
pi@raspberrypi ~/Pimoroni/piglow python bar.py Traceback (most recent call last): File "bar.py", line 8, in <module> piglow.leg_bar(0, x / 100.0) AttributeError: 'module' object has no attribute 'leg_bar' pi@raspberrypi ~/Pimoroni/piglow sudo python bar.py
Traceback (most recent call last):
File “bar.py”, line 8, in
piglow.leg_bar(0, x / 100.0)
AttributeError: ‘module’ object has no attribute 'leg_bar’
pi@raspberrypi ~/Pimoroni/piglow $

Geoff

You should delete the entire folder and run the one line installer as follows:

curl -sS get.pimoroni.com/piglow

then retry the examples freshly copied by the process.

You would need to delete the piglow.pyc file, too. I’m honestly not sure how you arrived at your present folder structure, since it’s certainly not what’s in the GitHub repo.

If deleting piglow.pyc doesn’t work then following RogueM’s advice is probably a good idea, although the command should be:

curl -sS get.pimoroni.com/piglow | bash

yep… told you I needed sleep…

I’m having the same issue, with a Pi 2 Model B. I’ve been through loads of stuff trying to get it to work. The only way I’ve managed to get them to work is with the boeerb test files from the command line using sudo. The beeerb test files work ok from sudo but I can’t get anything to work from Python shell.

The same files, piglow.py, piglow.pyc have appeared in the piglow folder. I’m happy adapting the files that work at the moment and running them from sudo, but it would be good to know why I can’t run from python. Any help appreciated, as this has been pretty frustrating!

sudo is basically the “simon says” of the Linux world. It has nothing especially to do with Python in particular, it’s not an interpreter, but rather a command that tells the bash environment something along the lines of: “run this thing as the root user.”

So when you type:

sudo python myscript.py

You’re actually running that script in python with elevated privileges.

When you then run either idle or python and attempt to execute Python commands you’re now running as an unprivileged user again.

The trick is, if you’re using idle, ( also called the Python IDE in the Pi mens these days ), is to launch it from the terminal using the sudo command, like so:

sudo idle

You should also never be seeing " piglow.py" or “pyglow.pyc” anywhere. The pyglow.py file is part of the library which should be installed somewhere tucked away in a special location where Python knows to look for it.

If you have a pyglow.py alongside your other Python scripts then you’ll inevitably run into problems where you save a script somewhere other than this folder and it can’t find the library anymore.

Similarly, if you name your own script piglow.py and run it, if it tries to import piglow it will end up importing itself which is almost always not the desired behaviour. We have fun times with this little gotcha in workshops :D