Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker build for numpy , pandas giving error

Tags:

docker

I have a Dockerfile in a directory called docker_test. The structure of docker_test is as follows:

M00618927A:docker_test i854319$ ls 
Dockerfile  hello_world.py

My dockerfile looks like below:

  ### Dockerfile 

# Created by Baktaawar 

# Pulling from base Python image 

FROM python:3.6.7-alpine3.6

# author of file
LABEL maintainer="Baktawar"

# Set the working directory of the docker image 
WORKDIR /docker_test
COPY . /docker_test


# packages that we need

RUN pip --no-cache-dir install numpy pandas jupyter


EXPOSE 8888

ENTRYPOINT ["python"]

CMD ["hello_world.py"]

I run the command

docker build -t dockerfile . 

It starts the building process but then gives the following error in not being able to get the numpy etc installed in the image

Sending build context to Docker daemon  4.096kB
Step 1/8 : FROM python:3.6.7-alpine3.6
 ---> 8f30079779ef
Step 2/8 : LABEL maintainer="Baktawar"
 ---> Running in 7cf081021b1e
Removing intermediate container 7cf081021b1e
 ---> 581cf24fa4e6
Step 3/8 : WORKDIR /docker_test
 ---> Running in 7c58855c4332
Removing intermediate container 7c58855c4332
 ---> dae70a34626b
Step 4/8 : COPY . /docker_test
 ---> 432b174b4869
Step 5/8 : RUN pip --no-cache-dir install numpy pandas jupyter
 ---> Running in 972efa9336ed
Collecting numpy
  Downloading https://files.pythonhosted.org/packages/cf/8d/6345b4f32b37945fedc1e027e83970005fc9c699068d2f566b82826515f2/numpy-1.16.2.zip (5.1MB)
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.6/site-packages/pkg_resources/__init__.py", line 357, 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-8c3o0ycd/pandas/setup.py", line 732, in <module>
        ext_modules=maybe_cythonize(extensions, compiler_directives=directives),
      File "/tmp/pip-install-8c3o0ycd/pandas/setup.py", line 475, in maybe_cythonize
        numpy_incl = pkg_resources.resource_filename('numpy', 'core/include')
      File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 1142, in resource_filename
        return get_provider(package_or_requirement).get_resource_filename(
      File "/usr/local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 359, 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-8c3o0ycd/pandas/
You are using pip version 18.1, however version 19.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
The command '/bin/sh -c pip --no-cache-dir install numpy pandas jupyter' returned a non-zero code: 1

How can I get this basic setup done?

like image 860
Baktaawar Avatar asked Mar 06 '19 21:03

Baktaawar


1 Answers

You basically need to install the following on alpine, in order to be able to install numpy:

apk --no-cache add musl-dev linux-headers g++

Try the following Dockerfile:

### Dockerfile
# Created by Baktawar
# Pulling from base Python image

FROM python:3.6.7-alpine3.6

# author of file
LABEL maintainer="Baktawar"

# Set the working directory of the docker image
WORKDIR /app
COPY . /app

# Install native libraries, required for numpy
RUN apk --no-cache add musl-dev linux-headers g++

# Upgrade pip
RUN pip install --upgrade pip

# packages that we need
RUN pip install numpy && \
    pip install pandas && \
    pip install jupyter

EXPOSE 8888

ENTRYPOINT ["python"]

CMD ["hello_world.py"]

You may find this gist interresting:

https://gist.github.com/orenitamar/f29fb15db3b0d13178c1c4dd611adce2

And this package on alpine, is also of interrest I think:

https://pkgs.alpinelinux.org/package/edge/community/x86/py-numpy

Update

In order to tag the image properly, use the syntax:

docker build -f <dockerfile> -t <tagname:tagversion> <buildcontext>

For you, this would be:

docker build -t mypythonimage:0.1 .
like image 53
Andreas Lorenzen Avatar answered Nov 16 '22 08:11

Andreas Lorenzen