Skip to content

ImportError: cannot import name 'PixelStrip' from 'rpi_ws281x' (unkown location) #559

@RaspberryNoobProgrammerLoser

Description

First of all: I am a total noob.

I have the Raspberry Pi 4 Model B. I just formatted its SD card and installed the latest bookworm 64-bit using the Imager tool from the Raspberry Pi website. I want to program an LED strip and I already wrote a bit of code 2 years ago. Now nothing works (WiFi doesn't work for some reason, WiFi network is not shown in list, but that's another problem....): I can't even start the famous "strandtest.py"...... it gives me the error message from the title:

ImportError: cannot import name 'PixelStrip' from 'rpi_ws281x' (unkown location)
(with the corresponding line of code: 'from rpi_ws281x import PixelStrip, Color)

I would be super grateful about some help!

EDIT: Oops, SOLVED!
I just had to install rpi_ws281x. First it was difficult , because pip didn't work. But then I found out (via the link in the error message) that since bookworm you need to do everything in virtual environments. So I had to install it via 'venv/bin/pip install' and then also start the script not using the Thonny editor (since it cannot work as root), but using the terminal via 'sudo /home/pi/Desktop/venv/bin/python <script_name>'.
For some reason, I also had to use the following lines of code to install 'neopixel':

sudo apt update && sudo apt upgrade -y
sudo apt install python3-dev python3-pip libportaudio2 libportaudiocpp0 portaudio19-dev -y

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions