Python: Fail to install python pandas package on alpine image 3.7.2-alpine3.9

Created on 15 Feb 2019  Â·  6Comments  Â·  Source: docker-library/python

Minimal reproduce:

FROM python:3.7.2-alpine3.9
RUN pip3 install pandas

Which lead to error:

Step 2/2 : RUN pip3 install pandas
 ---> Running in a27cff99becc
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/81/fd/b1f17f7dc914047cd1df9d6813b944ee446973baafe8106e4458bfb68884/pandas-0.24.1.tar.gz (11.8MB)
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 359, in get_provider
        module = sys.modules[moduleOrReq]
    KeyError: 'numpy'

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-mwz8syxn/pandas/setup.py", line 732, in <module>
        ext_modules=maybe_cythonize(extensions, compiler_directives=directives),
      File "/tmp/pip-install-mwz8syxn/pandas/setup.py", line 475, in maybe_cythonize
        numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 1144, in resource_filename
        return get_provider(package_or_requirement).get_resource_filename(
      File "/usr/local/lib/python3.7/site-packages/pkg_resources/__init__.py", line 361, in get_provider
        __import__(moduleOrReq)
    ModuleNotFoundError: No module named 'numpy'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-mwz8syxn/pandas/
The command '/bin/sh -c pip3 install pandas' returned a non-zero code: 1

Problem similar with tag 3.7.2-alpine3.8 too.

That works as expected with 3.7.2-slim! Like:

FROM python:3.7.2-slim
RUN pip3 install pandas
question

All 6 comments

Alpine Linux doesn't support PEP 513, every time we install packages on Alpine Linux we need re-building.

You could try this below:

FROM python:3.7.2-alpine3.9
RUN apk add --no-cache python3-dev libstdc++ && \
    apk add --no-cache g++ && \
    ln -s /usr/include/locale.h /usr/include/xlocale.h && \
    pip3 install numpy && \
    pip3 install pandas

You could try this below

As I say initially it build on 3.7.2-slim version without issues and additional packages.

His Dockerfile has the wrong FROM:, switch it to Alpine and that will build numpy and pandas.

The issue is pip uses manylinux1 wheels which doesn't support Alpine's musl https://github.com/docker-library/python/issues/341#issuecomment-426026398
Which means that you'll be installing the packages from source.

I would advise using python:slim which supports the manylinux1 wheels. and also saves considerable time and space comparatively.

$ docker images | grep python
python     3.7.2-alpine3.9      2d23e3e6584b        3 days ago          86.7MB
python     slim                 96c349a2897f        3 days ago          143MB

python     slim-pandas          7612a34bbac1        2 minutes ago       293MB
python     alpine-pandas        d0b3edf1be62        6 minutes ago       435MB
$ docker history python:slim-pandas
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
7612a34bbac1        13 minutes ago      /bin/sh -c pip3 install pandas                  149MB
. . .

$ docker history python:alpine-pandas
IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
d0b3edf1be62        17 minutes ago      /bin/sh -c apk add --no-cache python3-dev li…   348MB
. . .

sorry the FROM just a typo, fixed.

Closing since this question seems sufficiently answered, thanks @tao12345666333 for the Dockerfile

Was this page helpful?
0 / 5 - 0 ratings