ImportError: Importing the multiarray numpy extension module failed

Hi!

I’m trying to use the Raspberry Pi SenseHat with balenaOS. I installed the needed package (sense-hat) using the Dockerfile, which also installs numpy along the way. However upon running on boot a simple ‘hello world’ script that imports the sense hat package, I get the following error message:
ImportError: Importing the multiarray numpy extension module failed. Most likely you are trying to import a failed build of numpy. If you’re working with a numpy git repo, try git clean -xdf (removes all files not under version control). Otherwise reinstall numpy.

I tried installing numpy separately and also running git clean -xdf without any success. Any ideas as to how to fix this?

Thanks!

Hi there, can you share the Dockerfile either here or in PM so we can try to replicate the issue? I am guessing there might have been a problem while building the image, but it is difficult to say for sure. Did you see any errors while the application was building? Thanks!

I sent you my Dockerfile in PM. Thanks for the help!

Hi @sabtt,

I have taken a look at the Dockerfile you have included, and I noticed that you install sense-hat via both the OS package manager (apt-get) as well as the Python language package manager (pip3). I would guess these are conflicting with one another, can you try installing the sense-hat library just via pip3 and report back the results?

As an aside, you need not install numpy explicitly if the goal is just to pull it in as a dependency for sense-hat, since the package manager will do that for you typically.

Please let us know how that test goes!

Hi! After trying that it seems that there’s now an error installing Pillow (another dependency of sense-hat). Here’s some of the error messages I received:

  • Running setup.py install for pillow: finished with status ‘error’
  • The headers or library files could not be found for zlib, a required dependency when compiling Pillow from source.

Thanks for the help!

Nevermind, I had an error in the Dockerfile before. But I still get some errors:

Running setup.py install for numpy: finished with status ‘error’
And many others like the screenshot attached.


It seems like I need to add some environment variables in the dashboard?

Hey @sabtt it could be helpful if you could send me the version of the Dockerfile you are currently using via PM (or just post it here of you are comfortable with it) Just to be clear, is the error above coming from the pip3 install numpy step in the Dockerfile? As my colleague mentioned earlier you might not need to install that directly if you only need it as a dependency for sense-hat

Hey! All the packages were collected properly, the errors come from the installation step. I tried adding some environmental variables with a value of ‘on’ from the dashboard, and that got rid of the errors in the screenshot, but it brought back the zlib error from before. Update: this shouldn’t have worked since I’m in local mode and adding variables through the dashboard doesn’t apply to devices on local mode. This is the Dockerfile I’m currently using (I’m not installing numpy separately anymore):

Use an official Python runtime as a parent image

FROM balenalib/raspberrypi3-python:3.7.2

Set the working directory to /app

WORKDIR /app

Copy the current directory contents into the container at /app

COPY . /app

Install any needed packages specified in requirements.txt

RUN sudo apt-get update &&
sudo apt-get install libopenjp2-7 &&
pip3 install sense-hat rtimulib

Enable i2c and run hello_world.py

CMD modprobe i2c-dev && python3 /app/hello_world.py

Can you try adding zlib in your dockerfile? You can change sudo apt-get install libopenjp2-7 && to sudo apt-get install libopenjp2-7 zlib &&

I’m getting “E: Unable to locate package zlib”. Update: Apparently it needs to be zliblg. This throws me back to the environment variables and the errors from the screenshot.

I am running a couple of tests on this myself, to me it looks like both numpy and pillow fail in the install (possibly for different reasons), but the order in which it tries to install them may vary between builds (so it may seem like things are fixed when they really aren’t).

Ill update you as soon as I have some more information

Thanks a lot!

hey @sabtt , this isn’t an exactly perfect answer to your question, but if you change your Dockerfile to the following, it should build and work correctly I beleive:

#Use an official Python runtime as a parent image
FROM balenalib/raspberrypi3-python:3.5-jessie-run

#Set the working directory to /app
WORKDIR /app

#Copy the current directory contents into the container at /app
COPY . /app

#Install any needed packages specified in requirements.txt
RUN install_packages libopenjp2-7

RUN pip3 install sense-hat rtimulib --index-url https://www.piwheels.org/simple

#Enable i2c and run hello_world.py
CMD modprobe i2c-dev && python3 /app/hello_world.py

This makes use of the prebuilt python wheels from the great piwheels project https://www.piwheels.org/packages.html , the only downside is that it requires that you use python3.5 instead of 3.7.

Hi @shaunmulligan thanks for the help. Sorry about the late reply, but I just tried it and I’m still getting an error.


The problem still seems to be with the numpy installation.

Hi @sabtt , can you share the exact dockerfile you pushed that caused this error? or is this error at runtime when you import the library?

The error is at runtime. The image finished building, the error came from the device logs. I used the Dockerfile you wrote.

Ah, okay so it looks like you are missing libf77blas.so.3, from inside your running container can you run apt-get update && apt-get install libatlas-base-dev to install it and then try run your script again. If that works, then we can just add that to the Dockerfile

Now there’s an import error.

Blockquote ImportError: /usr/local/lib/python3.5/site-packages/numpy/random/mtrand.cpython-35m-arm-linux-gnueabihf.so: undefined symbol: PyFPE_jbuf

Sorry, this is being more problematic than I anticipated.

Hmm, this is so weird. I assume you are just trying to get a simple sensehat project up and running on your pi right? do you have any other requirements? I have a sense hat hear, so I’ll set one up and see if i can get it to work.

Yes, it’s nothing very complicated, I’m just trying to get it to work. This is my hello_world.py file:

from sense_hat import SenseHat
sense = SenseHat()
sense.show_message("Hello world")
sense.clear()
print("Hello world")