skip to Main Content

I am building a docker image to run a flask app, which is named dp-offsets for context. This flask app uses matplotlib. I have been unable to fully install matlplotlib despite including all of the necessary dependencies (i think). The code seems to be erroring on timestamp 791.9s due to bdist_wheel. I’m not sure why bdist_wheel is erroring, because I install wheel before I install matplotlib. Seen below is the terminal error, my requirements.txt file, and my Dockerfile.

Any help would be appreciated!

Docker File

FROM python:3.7.4-alpine

#Dependancies for matplotlib, pandas, and numpy
RUN apk add --no-cache --update 
    python3 python3-dev gcc 
    gfortran musl-dev g++ 
    libffi-dev openssl-dev 
    libxml2 libxml2-dev 
    libxslt libxslt-dev 
    jpeg-dev libjpeg make 
    libjpeg-turbo-dev zlib-dev

RUN pip install --upgrade cython
RUN pip install --upgrade pip
RUN pip install --upgrade setuptools

WORKDIR /dp-offsets

ADD . /dp-offsets

RUN pip install -r requirements.txt

CMD ["python", "app_main.py"]

Requirements.txt. File

wheel==0.37.0
flask==2.0.1
flask_bootstrap
form
numpy==1.21.2
matplotlib==3.4.3
pandas==1.3.2
flask_wtf==0.15.1
wtforms==2.3.3

Error Received

 > [8/8] RUN pip install -r requirements.txt:
#13 1.125 Collecting wheel==0.37.0
#13 1.713   Downloading wheel-0.37.0-py2.py3-none-any.whl (35 kB)
#13 1.874 Collecting flask==2.0.1
#13 1.975   Downloading Flask-2.0.1-py3-none-any.whl (94 kB)
#13 2.171      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 94.8/94.8 KB 444.0 kB/s eta 0:00:00
#13 2.348 Collecting flask_bootstrap
#13 2.458   Downloading Flask-Bootstrap-3.3.7.1.tar.gz (456 kB)
#13 3.130      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 456.4/456.4 KB 684.5 kB/s eta 0:00:00
#13 3.164   Preparing metadata (setup.py): started
#13 3.417   Preparing metadata (setup.py): finished with status 'done'
#13 3.585 Collecting form
#13 3.684   Downloading form-0.0.1.tar.gz (1.4 kB)
#13 3.699   Preparing metadata (setup.py): started
#13 3.929   Preparing metadata (setup.py): finished with status 'done'
#13 4.556 Collecting numpy==1.21.2
#13 4.641   Downloading numpy-1.21.2.zip (10.3 MB)
#13 15.18      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.3/10.3 MB 974.4 kB/s eta 0:00:00
#13 15.79   Installing build dependencies: started
#13 22.28   Installing build dependencies: finished with status 'done'
#13 22.28   Getting requirements to build wheel: started
#13 22.69   Getting requirements to build wheel: finished with status 'done'
#13 22.69   Preparing metadata (pyproject.toml): started
#13 23.05   Preparing metadata (pyproject.toml): finished with status 'done'
#13 23.34 Collecting matplotlib==3.4.3
#13 23.43   Downloading matplotlib-3.4.3.tar.gz (37.9 MB)
#13 53.17      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 37.9/37.9 MB 1.3 MB/s eta 0:00:00
#13 55.07   Preparing metadata (setup.py): started
#13 298.3   Preparing metadata (setup.py): still running...
#13 298.8   Preparing metadata (setup.py): finished with status 'done'
#13 299.1 Collecting pandas==1.3.2
#13 299.2   Downloading pandas-1.3.2.tar.gz (4.7 MB)
#13 302.7      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.7/4.7 MB 1.4 MB/s eta 0:00:00
#13 303.5   Installing build dependencies: started
#13 383.9   Installing build dependencies: still running...
#13 446.6   Installing build dependencies: still running...
#13 461.3   Installing build dependencies: finished with status 'done'
#13 461.4   Getting requirements to build wheel: started
#13 524.1   Getting requirements to build wheel: still running...
#13 524.5   Getting requirements to build wheel: finished with status 'done'
#13 524.5   Preparing metadata (pyproject.toml): started
#13 525.2   Preparing metadata (pyproject.toml): finished with status 'done'
#13 525.3 Collecting flask_wtf==0.15.1
#13 525.4   Downloading Flask_WTF-0.15.1-py2.py3-none-any.whl (13 kB)
#13 525.5 Collecting wtforms==2.3.3
#13 525.6   Downloading WTForms-2.3.3-py2.py3-none-any.whl (169 kB)
#13 525.7      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 169.1/169.1 KB 2.0 MB/s eta 0:00:00
#13 525.9 Collecting Werkzeug>=2.0
#13 526.1   Downloading Werkzeug-2.0.2-py3-none-any.whl (288 kB)
#13 526.3      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 288.9/288.9 KB 1.1 MB/s eta 0:00:00
#13 526.5 Collecting Jinja2>=3.0
#13 526.6   Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB)
#13 526.7      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 133.6/133.6 KB 1.5 MB/s eta 0:00:00
#13 526.9 Collecting itsdangerous>=2.0
#13 527.0   Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
#13 527.2 Collecting click>=7.1.2
#13 527.3   Downloading click-8.0.3-py3-none-any.whl (97 kB)
#13 527.3      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 97.5/97.5 KB 1.8 MB/s eta 0:00:00
#13 527.5 Collecting cycler>=0.10
#13 527.6   Downloading cycler-0.11.0-py3-none-any.whl (6.4 kB)
#13 527.7 Collecting kiwisolver>=1.0.1
#13 527.9   Downloading kiwisolver-1.3.2.tar.gz (54 kB)
#13 527.9      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 54.6/54.6 KB 3.0 MB/s eta 0:00:00
#13 527.9   Preparing metadata (setup.py): started
#13 530.1   Preparing metadata (setup.py): finished with status 'done'
#13 530.7 Collecting pillow>=6.2.0
#13 530.8   Downloading Pillow-9.0.0.tar.gz (49.5 MB)
#13 569.3      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 49.5/49.5 MB 1.2 MB/s eta 0:00:00
#13 570.4   Preparing metadata (setup.py): started
#13 570.7   Preparing metadata (setup.py): finished with status 'done'
#13 570.8 Collecting pyparsing>=2.2.1
#13 571.0   Downloading pyparsing-3.0.7-py3-none-any.whl (98 kB)
#13 571.1      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 98.0/98.0 KB 825.7 kB/s eta 0:00:00
#13 571.2 Collecting python-dateutil>=2.7
#13 571.3   Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
#13 571.6      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 KB 887.6 kB/s eta 0:00:00
#13 571.8 Collecting pytz>=2017.3
#13 572.0   Downloading pytz-2021.3-py2.py3-none-any.whl (503 kB)
#13 572.5      ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 503.5/503.5 KB 944.0 kB/s eta 0:00:00
#13 572.7 Collecting MarkupSafe
#13 572.8   Downloading MarkupSafe-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl (30 kB)
#13 573.1 Collecting dominate
#13 573.2   Downloading dominate-2.6.0-py2.py3-none-any.whl (29 kB)
#13 573.5 Collecting visitor
#13 573.6   Downloading visitor-0.1.3.tar.gz (3.3 kB)
#13 573.6   Preparing metadata (setup.py): started
#13 573.8   Preparing metadata (setup.py): finished with status 'done'
#13 574.0 Collecting importlib-metadata
#13 574.1   Downloading importlib_metadata-4.10.1-py3-none-any.whl (17 kB)
#13 574.2 Collecting six>=1.5
#13 574.3   Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
#13 574.5 Collecting typing-extensions>=3.6.4
#13 574.8   Downloading typing_extensions-4.0.1-py3-none-any.whl (22 kB)
#13 575.1 Collecting zipp>=0.5
#13 575.6   Downloading zipp-3.7.0-py3-none-any.whl (5.3 kB)
#13 575.6 Building wheels for collected packages: numpy, matplotlib, pandas, flask_bootstrap, form, kiwisolver, pillow, visitor
#13 575.6   Building wheel for numpy (pyproject.toml): started
#13 657.8   Building wheel for numpy (pyproject.toml): still running...
#13 720.6   Building wheel for numpy (pyproject.toml): still running...
#13 777.1   Building wheel for numpy (pyproject.toml): finished with status 'done'
#13 777.1   Created wheel for numpy: filename=numpy-1.21.2-cp37-cp37m-linux_x86_64.whl size=21275305 sha256=82ac227d9585fb707983648e7ab6b8ff47b953a1d5d687409339ad505a8467b4
#13 777.1   Stored in directory: /root/.cache/pip/wheels/6b/8c/55/e7f441ea696acba3eba6931857214e3b33dcfe1e971b663032
#13 777.1   Building wheel for matplotlib (setup.py): started
#13 791.9   Building wheel for matplotlib (setup.py): finished with status 'error'
#13 791.9   error: subprocess-exited-with-error
#13 791.9
#13 791.9   × python setup.py bdist_wheel did not run successfully.
#13 791.9   │ exit code: 1
#13 791.9   ╰─> [861 lines of output]
#13 791.9
#13 791.9       Edit setup.cfg to change the build options; suppress output with --quiet.
#13 791.9
#13 791.9       BUILDING MATPLOTLIB
#13 791.9         matplotlib: yes [3.4.3]
#13 791.9             python: yes [3.7.4 (default, Aug 21 2019, 00:19:59)  [GCC 8.3.0]]
#13 791.9           platform: yes [linux]
#13 791.9              tests: no  [skipping due to configuration]
#13 791.9             macosx: no  [Mac OS-X only]

The Error continues for a bit longer. Below is the final output

#13 1427.6       UPDATING build/lib.linux-x86_64-3.7/matplotlib/_version.py
#13 1427.6       set build/lib.linux-x86_64-3.7/matplotlib/_version.py to '3.4.3'
#13 1427.6       running build_ext
#13 1427.6       gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.7m -c /tmp/tmpzzp8tz7k.cpp -o tmp/t
mpzzp8tz7k.o -fvisibility=hidden
#13 1427.6       gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.7m -c /tmp/tmpqr5gbp_k.cpp -o tmp/t
mpqr5gbp_k.o -fvisibility-inlines-hidden
#13 1427.6       gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -DTHREAD_STACK_SIZE=0x100000 -fPIC -I/usr/local/include/python3.7m -c /tmp/tmptx14kry1.cpp -o tmp/t
mptx14kry1.o -flto
#13 1427.6       error: Failed to download any of the following: ['http://www.qhull.org/download/qhull-2020-src-8.0.2.tgz'].  Please download one of these urls and extract it into 'bui
ld/' at the top-level of the source repository.
#13 1427.6       [end of output]
#13 1427.6
#13 1427.6   note: This error originates from a subprocess, and is likely not a problem with pip.
#13 1427.7 error: legacy-install-failure
#13 1427.7
#13 1427.7 × Encountered error while trying to install package.
#13 1427.7 ╰─> matplotlib
#13 1427.7
#13 1427.7 note: This is an issue with the package mentioned above, not pip.
#13 1427.7 hint: See above for output from the failure.
------
executor failed running [/bin/sh -c pip install -r requirements.txt]: exit code: 1

2

Answers


  1. Chosen as BEST ANSWER

    For anyone that encounters this error, and later finds this post.

    I was never able to solve this problem with using Matplotlib in my Docker container. Instead, I abandoned Matplotlib and used Plotly 5.8.0.


  2. There are multiple dependencies for running matplotlib in Docker.

    I will share a minimal working example Dockerfile, and explain the steps below.

    FROM ubuntu:20.04
    
    # setup env
    RUN apt update -y
    RUN apt install -y software-properties-common
    
    # install Python3+ and pip
    RUN add-apt-repository universe
    RUN apt install -y python3.9 python3-pip
    
    # install matplotlib
    RUN apt install -y libjpeg-dev zlib1g-dev
    RUN pip3 install --upgrade pip setuptools wheel
    RUN pip3 install matplotlib
    

    The first section is to setup the Ubuntu environment and not specific to matplotlib.

    The second block is to configure the Python environment. It may be necessary to override the default Python version inside the container (e.g. on older Ubuntu versions). To do that, you can add these commands after the second block:

    RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1
    RUN update-alternatives --set python3 /usr/bin/python3.9
    

    The last section is for installing matplotlib. Installing libjpeg and upgrading build tools is to ensure the various dependencies can be installed also. The original question Dockerfile seems to be missing the step to upgrade wheel and the error message implies the same. After that, matplotlib installation should complete successfully.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search