I am making a docker image that needs pandas and numpy but the installation via pip takes around 20 mins which is too long for my use case. I then opt to install pandas and numpy from alpine package repo but it seems to fail to import numpy correctly.
Here is my Dockerfile:
# syntax=docker/dockerfile:experimental
FROM python:3.9.5-alpine as base
FROM base as builder
RUN apk add build-base gcc musl-dev
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --target="/install" django
FROM base
RUN apk add py3-pandas py3-numpy
COPY --from=builder /install /usr/local/lib/python3.9/site-packages
ENV PYTHONPATH "${PYTHONPATH}:/usr/lib/python3.9/site-packages"
CMD ["python"]
When I try to import pandas, which depends on numpy, gives me the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.9/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/usr/local/bin/python"
* The NumPy version is: "1.20.3"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
and the error if I import numpy:
Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/numpy/core/__init__.py", line 22, in <module>
from . import multiarray
File "/usr/lib/python3.9/site-packages/numpy/core/multiarray.py", line 12, in <module>
from . import overrides
File "/usr/lib/python3.9/site-packages/numpy/core/overrides.py", line 7, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.9/site-packages/numpy/__init__.py", line 145, in <module>
from . import core
File "/usr/lib/python3.9/site-packages/numpy/core/__init__.py", line 48, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.9 from "/usr/local/bin/python"
* The NumPy version is: "1.20.3"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
I am already at wits end trying to figure out what I missed and did wrong. I already tried the troubleshooting tips in the url given by the error trace but nothing seems to solve the issue.
Any help is greatly appreciated.