0

I want to use the python package 'numpy'. After a bit of research, I found that using apt install python3-numpy seems to be the recommended way of installing it on the raspberry pi 3 (within a docker container based on 'arm32v7/python:latest').

The apt installation command seems to work without any issues, but once I try to import numpy in python, I get a ModuleNotFoundError: No mule named 'numpy'.

How can I get numpy to work in python on my setup?

Full log:

pi@raspberrypi:/data/docker-apps/slammer $ uname -a
Linux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l GNU/Linux
pi@raspberrypi:/data/docker-apps/slammer $ docker run --rm -it arm32v7/python bash
root@3581843f74b6:/# apt update
Get:1 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:2 http://deb.debian.org/debian buster InRelease [122 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://security.debian.org/debian-security buster/updates/main armhf Packages [262 kB]
Get:5 http://deb.debian.org/debian buster/main armhf Packages [7698 kB]
Get:6 http://deb.debian.org/debian buster-updates/main armhf Packages [9488 B]
Fetched 8208 kB in 11s (775 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@3581843f74b6:/# apt list --upgradable
Listing... Done
libtiff-dev/stable 4.1.0+git191117-2~deb10u2 armhf [upgradable from: 4.1.0+git191117-2~deb10u1]
libtiff5/stable 4.1.0+git191117-2~deb10u2 armhf [upgradable from: 4.1.0+git191117-2~deb10u1]
libtiffxx5/stable 4.1.0+git191117-2~deb10u2 armhf [upgradable from: 4.1.0+git191117-2~deb10u1]
root@3581843f74b6:/# apt install python3-numpy
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libblas3 libgfortran5 liblapack3 python3-pkg-resources
Suggested packages:
  gfortran python-numpy-doc python3-dev python3-pytest python3-numpy-dbg python3-setuptools
The following NEW packages will be installed:
  libblas3 libgfortran5 liblapack3 python3-numpy python3-pkg-resources
0 upgraded, 5 newly installed, 0 to remove and 3 not upgraded.
Need to get 4008 kB of archives.
After this operation, 15.3 MB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://deb.debian.org/debian buster/main armhf libgfortran5 armhf 8.3.0-6 [213 kB]
Get:2 http://deb.debian.org/debian buster/main armhf libblas3 armhf 3.8.0-2 [109 kB]
Get:3 http://deb.debian.org/debian buster/main armhf liblapack3 armhf 3.8.0-2 [1631 kB]
Get:4 http://deb.debian.org/debian buster/main armhf python3-pkg-resources all 40.8.0-1 [153 kB]
Get:5 http://deb.debian.org/debian buster/main armhf python3-numpy armhf 1:1.16.2-1 [1903 kB]
Fetched 4008 kB in 1s (3194 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libgfortran5:armhf.
(Reading database ... 24344 files and directories currently installed.)
Preparing to unpack .../libgfortran5_8.3.0-6_armhf.deb ...
Unpacking libgfortran5:armhf (8.3.0-6) ...
Selecting previously unselected package libblas3:armhf.
Preparing to unpack .../libblas3_3.8.0-2_armhf.deb ...
Unpacking libblas3:armhf (3.8.0-2) ...
Selecting previously unselected package liblapack3:armhf.
Preparing to unpack .../liblapack3_3.8.0-2_armhf.deb ...
Unpacking liblapack3:armhf (3.8.0-2) ...
Selecting previously unselected package python3-pkg-resources.
Preparing to unpack .../python3-pkg-resources_40.8.0-1_all.deb ...
Unpacking python3-pkg-resources (40.8.0-1) ...
Selecting previously unselected package python3-numpy.
Preparing to unpack .../python3-numpy_1%3a1.16.2-1_armhf.deb ...
Unpacking python3-numpy (1:1.16.2-1) ...
Setting up python3-pkg-resources (40.8.0-1) ...
Setting up libgfortran5:armhf (8.3.0-6) ...
Setting up libblas3:armhf (3.8.0-2) ...
update-alternatives: using /usr/lib/arm-linux-gnueabihf/blas/libblas.so.3 to provide /usr/lib/arm-linux-gnueabihf/libblas.so.3 (libblas.so.3-arm-linux-gnueabihf) in auto mode
Setting up liblapack3:armhf (3.8.0-2) ...
update-alternatives: using /usr/lib/arm-linux-gnueabihf/lapack/liblapack.so.3 to provide /usr/lib/arm-linux-gnueabihf/liblapack.so.3 (liblapack.so.3-arm-linux-gnueabihf) in auto mode
Setting up python3-numpy (1:1.16.2-1) ...
Processing triggers for libc-bin (2.28-10) ...
root@3581843f74b6:/# python3
Python 3.9.2 (default, Mar 12 2021, 15:39:15)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>>

Update 1: Updating (apt-get update && apt-get upgrade) the pi didn't change the problem:

Linux raspberrypi 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux
pi@raspberrypi:~ $ docker run --rm -it arm32v7/python:latest bash
root@a004ed0810a9:/# uname -a
Linux a004ed0810a9 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux
root@a004ed0810a9:/# apt update
Get:1 http://deb.debian.org/debian buster InRelease [122 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Get:3 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:4 http://deb.debian.org/debian buster/main armhf Packages [7698 kB]
Get:5 http://security.debian.org/debian-security buster/updates/main armhf Packages [262 kB]
Get:6 http://deb.debian.org/debian buster-updates/main armhf Packages [9488 B]
Fetched 8208 kB in 8s (1088 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
root@a004ed0810a9:/# apt install -y python3-numpy
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libblas3 libgfortran5 liblapack3 python3-pkg-resources
Suggested packages:
  gfortran python-numpy-doc python3-dev python3-pytest python3-numpy-dbg python3-setuptools
The following NEW packages will be installed:
  libblas3 libgfortran5 liblapack3 python3-numpy python3-pkg-resources
0 upgraded, 5 newly installed, 0 to remove and 3 not upgraded.
Need to get 4008 kB of archives.
After this operation, 15.3 MB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main armhf libgfortran5 armhf 8.3.0-6 [213 kB]
Get:2 http://deb.debian.org/debian buster/main armhf libblas3 armhf 3.8.0-2 [109 kB]
Get:3 http://deb.debian.org/debian buster/main armhf liblapack3 armhf 3.8.0-2 [1631 kB]
Get:4 http://deb.debian.org/debian buster/main armhf python3-pkg-resources all 40.8.0-1 [153 kB]
Get:5 http://deb.debian.org/debian buster/main armhf python3-numpy armhf 1:1.16.2-1 [1903 kB]
Fetched 4008 kB in 1s (3224 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libgfortran5:armhf.
(Reading database ... 24344 files and directories currently installed.)
Preparing to unpack .../libgfortran5_8.3.0-6_armhf.deb ...
Unpacking libgfortran5:armhf (8.3.0-6) ...
Selecting previously unselected package libblas3:armhf.
Preparing to unpack .../libblas3_3.8.0-2_armhf.deb ...
Unpacking libblas3:armhf (3.8.0-2) ...
Selecting previously unselected package liblapack3:armhf.
Preparing to unpack .../liblapack3_3.8.0-2_armhf.deb ...
Unpacking liblapack3:armhf (3.8.0-2) ...
Selecting previously unselected package python3-pkg-resources.
Preparing to unpack .../python3-pkg-resources_40.8.0-1_all.deb ...
Unpacking python3-pkg-resources (40.8.0-1) ...
Selecting previously unselected package python3-numpy.
Preparing to unpack .../python3-numpy_1%3a1.16.2-1_armhf.deb ...
Unpacking python3-numpy (1:1.16.2-1) ...
Setting up python3-pkg-resources (40.8.0-1) ...
Setting up libgfortran5:armhf (8.3.0-6) ...
Setting up libblas3:armhf (3.8.0-2) ...
update-alternatives: using /usr/lib/arm-linux-gnueabihf/blas/libblas.so.3 to provide /usr/lib/arm-linux-gnueabihf/libblas.so.3 (libblas.so.3-arm-linux-gnueabihf) in auto mode
Setting up liblapack3:armhf (3.8.0-2) ...
update-alternatives: using /usr/lib/arm-linux-gnueabihf/lapack/liblapack.so.3 to provide /usr/lib/arm-linux-gnueabihf/liblapack.so.3 (liblapack.so.3-arm-linux-gnueabihf) in auto mode
Setting up python3-numpy (1:1.16.2-1) ...
Processing triggers for libc-bin (2.28-10) ...
root@a004ed0810a9:/# python3
Python 3.9.2 (default, Mar 12 2021, 15:39:15)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
>>>
1
  • No one knows what you have done. You are obviously using an old Raspberry Pi OS and installed some other python version. If you used the current Raspberry Pi OS it would work! If you want fancy addons you need to follow their rules.
    – Milliways
    Mar 14, 2021 at 9:17

1 Answer 1

1

It seems that the python version provided by arm32v7/python:latest just doesn't play nice with packages installed via apt. I assume this is because the apt-managed python version is older than the one provided with the image.

When I use debian as a base image and apt install python3 python3-numpy it works.

Full Dockerfile:

FROM debian

COPY requirements-additional.txt /tmp/reqs.txt

RUN apt-get update && apt-get install -y --no-install-recommends \
  python3 \
  python3-pip \
  python3-numpy \
  && apt-get clean \
  && rm -rf /var/lib/apt/lists/*
RUN pip3 install -r /tmp/reqs.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.