I have done the installs and when I run the standtest.py I get the following:
%Run standtest.py
Traceback (most recent call last):
File “/root/standtest.py”, line 9, in
from rpi_ws281x import *
ModuleNotFoundError: No module named ‘rpi_ws281x’
I have done the installs and when I run the standtest.py I get the following:
%Run standtest.py
Traceback (most recent call last):
File “/root/standtest.py”, line 9, in
from rpi_ws281x import *
ModuleNotFoundError: No module named ‘rpi_ws281x’
Hi Test,
Welcome to the Forum! This one still might not be compatible with the latest OS. Are you using Bookworm?
Hi Robert,
Welcome to the Forum! In your command terminal you need to run these commands.
sudo pip3 install rpi_ws281x
sudo pip3 install adafruit-circuitpython-neopixel
sudo python3 -m pip install --force-reinstall adafruit-blinka
Pip is no longer supported on Bookworm so you may need to flash a different OS if this doesn’t work.
I have run all those in a venv and they install and yet I get that error
Does rpi_ws281x show up when you run pip3 list? I’ve seen installing and uninstalling this package has worked in some other forums.
It does show up when I run pip list. when I try to remove it, it says cannot locate package. It also does that when trying to install it.
Hi Robert,
I’d recommend starting again with a clean image of the OS. It sounds like it hasn’t been installed correctly so that’s preventing you from uninstalling it. With a fresh OS we can also run through installing it in a more controlled manner.
Hello, I was unable to find any solution for this: how do I activate the virtual environment and subsequently the strandtest.py upon startup of my system? Ultimately I want to run this script headless, and its been nothing but running around like a “headless” chicken ![]()
Also, thank you for this post/guide! Its terrific ![]()
Thus far, I have researched startup script in venv methods with (1) crontab -e adding @reboot to the bottom line, (2) creating .sh shell scripts (!# bin/bash), and (3) the method of /home/pi/.config/autostart/ using [Desktop Entry]… but to no avail. I’m also having trouble running the strandtest.py in a terminal window, after I activate the virtual environment. Maybe therein lies my problem?!
Hey @Roy285735, welcome to the forums!
It sounds unusual you can’t run standtest.py in the terminal. Would you be able to tell us more about that and share the error you receive when you try this?
As for running python scripts on start-up, I have had luck in the past using these resources:
https://forums.raspberrypi.com/viewtopic.php?t=314455
Hope this helps! ![]()
Thanks for the reply!
The way I am able to run strandtest.py is by following the above instructions (after installing the required packages):
If I stay in the terminal, activate my venv, then write >> python3 /home/pi/myproject/strandtest.py then this permissions error comes up:
(env) pi@raspberrypi:~ $ python3 /home/pi/myproject/strandtest.py
Can't open /dev/mem: Permission denied
Traceback (most recent call last):
File "/home/pi/myproject/strandtest.py", line 90, in <module>
strip.begin()
File "/home/pi/env/lib/python3.11/site-packages/rpi_ws281x/rpi_ws281x.py", line 143, in begin
raise RuntimeError('ws2811_init failed with code {0} ({1})'.format(resp, str_resp))
RuntimeError: ws2811_init failed with code -5 (mmap() failed)
Segmentation fault
You can also view the packages from a pip list, they are present:
(env) pi@raspberrypi:~ $ pip list
Package Version
---------------------------------------- -------
Adafruit-Blinka 8.50.0
adafruit-circuitpython-busdevice 5.2.10
adafruit-circuitpython-connectionmanager 3.1.2
adafruit-circuitpython-neopixel 6.3.12
adafruit-circuitpython-pixelbuf 2.0.6
adafruit-circuitpython-requests 4.1.8
adafruit-circuitpython-typing 1.11.2
Adafruit-PlatformDetect 3.75.0
Adafruit-PureIO 1.1.11
binho-host-adapter 0.1.6
keyboard 0.13.5
pip 23.0.1
pyftdi 0.56.0
pyserial 3.5
pyusb 1.2.1
RPi.GPIO 0.7.1
rpi-ws281x 5.0.0
setuptools 66.1.1
sysv-ipc 1.1.0
typing_extensions 4.12.2
p.s. thank you for the documentation about running start up scripts! I’ll dig into that and learn if a systemd service can help me activate the virtual environment and run this script on a headless setup.
Hey @Roy285735 ![]()
This is the line of code that jumped out to me.
Can’t open /dev/mem: Permission denied
dev/mem is the path that gives access to physical memory on the machine. You need to access memory when you are initializing your strip : strip.begin()
Linux demands that you have the right permissions to grab this file and your user doesn’t have the permissions at the moment.
The way others are resolving this in the thread is running the command as root.
sudo python3 /home/pi/myproject/strandtest.py
There are ways you can give your current user permission to access that file.
I searched the error and this thread came up.
Does this work for your on venv
Hello,
This is the response when I added the right permissions using sudo:
(env) pi@raspberrypi:~ $ sudo python3 /home/pi/myproject/strandtest.py
Traceback (most recent call last):
File "/home/pi/myproject/strandtest.py", line 8, in <module>
from rpi_ws281x import *
ModuleNotFoundError: No module named 'rpi_ws281x'
Also, this morning revealed a new bug: the OneStripNeopixel.py script no longer works. I was running this last night with no issues, and suddenly it is throwing this error:
(env) pi@raspberrypi:~ $ sudo python3 /home/pi/myproject/OneStripNeopixel.py
Traceback (most recent call last):
File "/home/pi/myproject/OneStripNeopixel.py", line 3, in <module>
import board
ModuleNotFoundError: No module named 'board'
The module ‘board’ is indeed being called in line3 of the code, but was never installed nor shows up in pip list, however I followed this tutorial to a T and it was working yesterday. Any hints?
Hey @Roy285735
Let’s start at the top.
Before you ran a pip list and showed those packages were installed.
my claim is that if you ran a sudo pip list bash would inform you that the super user (sudo) does not have any of those package installed.
Easy fix! Let’s install them as sudo.
sudo pip install rpi_ws281x #possibly need to specify pip3
My hope is that this will fix both your errors since I think the board lib is a dependency of rpi_ws281x.
THANK YOU @Pixmusix !
Problem 100% resolved, I can now activate scripts successfully in the terminal and those dependency errors are gone. This was indeed a misunderstanding (on my part) of installing packages (and running pip list) within a virtual environment vs. installing these packages as a super user in order to execute from a terminal.
Merry Christmas to you all!
![]()
Hi,
with Debian Bookworm, and I accept if I’m wrong, you are forced to use python3 (and pip) in a virtual environment.
I used these commands to install :-
Then, to use python3 you need to specify the virtual environment you created (in my case /python3/bin) to run python commands
Hi @Earle218464,
Welcome to the forum! I’m not quite sure what hiccup you are running into. It looks like you’ve done the right thing so far.
@Jack I read this as @Earle218464 being a champion who ran into some challenges and left a note behind for the next wonderer. ![]()
Hello @Pixmusix
I am running into the same Module Not Found errors as listed above, and yes, when I run a sudo pip list, the packages are not installed. However, when I try to use “sudo pip install rpi_ws281x” it tells me that it is an externally managed environment (even though I have a virtual environment activated).
Please let me know if I can solve this issue. Also, if @Roy285735 has any information on how exactly they did this, let me know.
I’m pretty new to Raspberry Pi, so I really appreciate the work you guys do on the forms. Happy Easter!
Hey Jake.
Good question.
I’m assuming you’re running raspberry pi os.
Pip, a package manager old enough to default on a mortgage in the peak of the GFC, hasn’t exactly figured out a graceful way of managing virtual environments.
I’ve found pipx to work for me, which does attempt to handle virtual environments for you.
Alternatively @Jaryd recently wrote this article of VEs.
You may find the solution following his process and see if there is a step you missed.
It worked! Thanks so much for the timely response. As I said, I’m pretty new to Raspberry Pi so I honestly have little to no clue what I’m doing. I’ll explain how it worked for any people who see this down the line:
I activated the virtual environment and input “sudo thonny”. I then followed the guide posted above, and when he says to restart thonny, I just closed the window and reinput “sudo thonny” into the terminal. Worked great after that.
Again, @Pixmusix and @Jaryd can’t thank you enough. Been fiddling around with the Raspberry Pi for a few weeks trying to make it work for a school project, and you may have just saved me since it’s due mid-May. Have a great one!