Timothy Lukas H.
Timothy Lukas H.

Reputation: 684

ImportError: No module named 'board' (AdaFruit)

I run the setup from this website to get my arduino to use AdaFruit LEDs. And also run:

sudo pip3 install adafruit-circuitpython-neopixel

I then made this python code:

import board
import neopixel
pixels = neopixel.NeoPixel(board.D18, 12, brightness=0.2)
pixels[0] = (255, 0, 0)

And then executed it with python filename.py And got the error:

ImportError: No module named 'board'

I then thought I maybe need to use python3 (Because it every where says too)

So I typed:

python3 light-test.py

This time got some more output, but in the end again an ImportError:

 File "light-test.py", line 2, in <module>
 import neopixel
 File "/usr/local/lib/python3.5/dist-packages/neopixel.py", line 34, in           
 <module>
 from neopixel_write import neopixel_write
 File "/home/pi/.local/lib/python3.5/site-packages/neopixel_write.py", line 
 15, in <module>
 from adafruit_blinka.microcontroller.raspi_23 import neopixel as _neopixel
 File "/home/pi/.local/lib/python3.5/site- 
 packages/adafruit_blinka/microcontroller/raspi_23/neopixel.py", line 3, in 
 <module>
 import _rpi_ws281x as ws
 ImportError: No module named '_rpi_ws281x'

So I don't know know what I am doing wrong.

Upvotes: 9

Views: 72897

Answers (4)

ConcernedHobbit
ConcernedHobbit

Reputation: 874

If you're missing the 'board' module, that can be globally installed with the following pip3 command:

sudo pip3 install --break-system-packages adafruit-blinka

Upvotes: 9

Scigrapher
Scigrapher

Reputation: 2116

If you've already followed https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi and passed the Blinka test, then I suspect the problem you're hitting is sudo/account-related.

The problem I hit is that the directions on Adafruit install packages for the current user but you need to run Python with sudo to make use of them. Complicating this is that Raspberry OS (rightfully) doesn't want you to install Python packages globally via pip.

To fix it, I basically followed the directions on https://learn.adafruit.com/circuitpython-on-raspberrypi-linux/installing-circuitpython-on-raspberry-pi. It creates the virtual environment "env" where all the required packages are installed. Then I used sudo env/bin/python <script> to run my script. That allows running with the privileges required to access the hardware while still being able to see the Python packages.

Upvotes: 0

Mainmeister
Mainmeister

Reputation: 21

I found that there was a board module already installed on my system (the wrong one). I deleted the board module and reinstalled adafruit-blinka to fix this.

Upvotes: 1

jarcobi889
jarcobi889

Reputation: 835

You're right to use Python3 instead of Python2.

One solution suggested here is to build the rpi_ws281x code from source.

Before that, however, you could try running as a super user/ administrator as suggested here.

Upvotes: 7

Related Questions