问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/53045343/adafruit-raspberry-pi-neopixel-library-throws-error-importerror-no-module-name