d-vine
d-vine

Reputation: 5547

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.

Upvotes: 4

Views: 18289

Answers (2)

John Foutch
John Foutch

Reputation: 11

I was going through the same tutorial as you, however had to remove and re-install rpi_ws281x to get it to work.

sudo pip3 uninstall rpi_ws281x

sudo pip3 install rpi_ws281x

Seeing you specifically use "python3" tipped me off to use pip3...

Upvotes: 1

d-vine
d-vine

Reputation: 5547

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.

Upvotes: 2

Related Questions