Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adafruit raspberry-pi neopixel library throws error "ImportError: No module named _rpi_ws281x"

I ran into this problem when following the Adafruit Neopixel tutorial: https://learn.adafruit.com/neopixels-on-raspberry-pi/python-usage

I double checked having all the requirements installed but still got an error:

ImportError: No module named _rpi_ws281x

It took me quite a while to piece the solution together that's why I wanted to document it here. See answer below.

like image 918
d-vine Avatar asked Sep 05 '25 03:09

d-vine


1 Answers

The solution is to rebuild and reinstall the rpi_ws281x library from the source (as suggested in various github issues e.g. https://github.com/jgarff/rpi_ws281x/issues/225)

Let's walk through this:

I'm assuming you followed the Adafruit Neopixel tutorial and have installed all the relevant python3 stuff, especially the setup tools.

We will need a couple of additional dependencies installed on your pi to build the library.

sudo apt-get install python-dev git scons swig

Clone the rpi_ws281x repository

git clone https://github.com/jgarff/rpi_ws281x.git

and change into the rpi_ws281x directory

cd rpi_ws281x

Next let's build the C library

sudo scons

Now change into the library's python directory

cd python

Build the python module (remember to use python3)

sudo python3 setup.py build

And install it

sudo python3 setup.py install

That's it! The error should be gone.

like image 145
d-vine Avatar answered Sep 08 '25 02:09

d-vine