Working my way through the Raphael kit on a new Raspberry Pi 5. Currently doing the 1.1.6_LedMatrix project with Python. Following the instructions after building the circuit, I did the software installation and created the virtual environment and activated it. When i run the script for the project I am unable to import from the luma.core.interface.serial package. I can look in the venv and see it, but Python can’t, apparently. I am an experienced developer but pretty new to the Pi and Linux and I need some help.
The error is
File “/home/rick/raphael-kit/python-pi5/1.1.6_LedMatrix.py”, line 1, in
from luma.core.interface.serial import sp1, noop
ModuleNotFoundError: No module named ‘luma’
Thanks!
-
Have you enabled the SPI service before running the example code?
Please execute the sudo raspi-config command to enable SPI. You can follow the instructions in this tutorial link:
SPI Configuration
-
Have you installed the Luma.LED_Matrix module before running the code?
Please install it by following the instructions in this tutorial link:
Install the Libraries
Once you have completed these two steps, please run the 1.1.6_LedMatrix project and check how it works.
As I said. I followed the instructions, so yes I enabled SPI and installed the Luma.LED_Matrix module before running the code. The error message is from running the code after completing those steps.
My next step, later today, is to delete the venv and do the software installation again.
Thanks!
We have verified the tutorial, and it works correctly.
Please note the following:
In Step 1 of installing the Luma.LED_Matrix module, when running sudo usermod -a -G spi,gpio pi, replace “pi” with your own username instead of copying the command directly.
For example, if your username is “only”, run:
sudo usermod -a -G spi,gpio only
Then continue with the tutorial steps.
After completing all instructions for the Luma.LED_Matrix module, run:
cd ~/raphael-kit/python-pi5
sudo ~/my_env/bin/python3 1.1.6_LedMatrix.py
If you see the error:
ModuleNotFoundError: No module named ‘spidev’
Run this command:
sudo ~/my_env/bin/pip3 install spidev
Then run the example 1.1.6_LedMatrix.py again to check the result.
I deleted and re-created the virtual environment and installed spidev in the virtual environment. Then when I ran 1.1.6_LedMatrix.py it started with no errors. However, I discovered that use of sudo to run the script was unnecessary. I assumed that this was because of the “usermod” command that was executed as part of the installation of the Luma.LED_Matrix module
Installing spidev in the virtual environment was not a documented step. The SPI configuration changes were made before the virtual environment was created.
Thanks for your help.
We are glad that you resolved the issue.
You believe that there is no need to run the script with sudo, and you speculate that this is due to the usermod command executed when installing the Luma.LED_Matrix module (adding the user to the spi and gpio user groups). This speculation is entirely reasonable—spi and gpio are user groups in Raspberry Pi that control hardware interfaces. Once a user is added to these groups, they can access SPI and GPIO resources without administrator privileges (sudo), so there’s no need to use sudo when running the script.
If you rebuild the virtual environment later, we recommend installing the spidev and Luma.LED_Matrix modules first in the new environment (you can run sudo ~/new_environment_path/bin/pip3 install spidev luma.led-matrix) to avoid errors due to missing dependencies.