Home > database >  Why does Docker build struggle to locate so many Python modules?
Why does Docker build struggle to locate so many Python modules?

Time:10-21

I keep seeing an error message during my docker build, at the part where docker tries to install my requirements.txt file that says Module Not Found. However, half of the time the version of the module it says it can't find is in the list of versions available.

I keep trying older versions and eventually I'll find one that works but then the same thing will happen on the next package. It's taking hours to try and build one container which surely can't be right. I'm assuming it might be something to do with packages might not be passing between different layers of the containers, but I'm new to Docker so can't tell if this is the issue or how to fix it.

I'm using WSL2 (Ubuntu 20.04) to build a flask application in Python (well technically it's a Plotly Dash app but I've read it works the same as flask). I have a Windows 10 machine and I've ensured that Docker is set to be compatible with WSL2 and Ubuntu. I've pasted a few of the many errors I've been getting below, as well as my current requirements.txt, Dockerfile and file structure.

I'd like to know how to prevent this message from keep coming up and how to know which package is compatible with Docker? Any help would be appreciated.

Some of my error messages that I'm seeing are:

ERROR: Could not find a version that satisfies the requirement pandas==1.0.5 (from versions: 0.1, 0.2, 0.3.0, 0.4.0, 
0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 0.10.1, 
0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 0.17.1, 
0.18.0, 0.18.1, 0.19.0, 0.19.1, 0.19.2, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 0.23.1, 
0.23.2, 0.23.3, 0.23.4, 0.24.0, 0.24.1, 0.24.2, 0.25.0, 0.25.1, 0.25.2, 0.25.3, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 
1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5)
#12 50.80 ERROR: No matching distribution found for pandas==1.0.5

Or:

#12 17.32 ERROR: Could not find a version that satisfies the requirement pandas==1.3.3 (from versions: 0.1, 0.2, 0.3.0, 
0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.6.0, 0.6.1, 0.7.0, 0.7.1, 0.7.2, 0.7.3, 0.8.0, 0.8.1, 0.9.0, 0.9.1, 0.10.0, 
0.10.1, 0.11.0, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 
0.17.1, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 0.19.2, 0.20.0, 0.20.1, 0.20.2, 0.20.3, 0.21.0, 0.21.1, 0.22.0, 0.23.0, 
0.23.1, 0.23.2, 0.23.3, 0.23.4, 0.24.0, 0.24.1, 0.24.2, 0.25.0, 0.25.1, 0.25.2, 0.25.3, 1.0.0, 1.0.1, 1.0.2, 1.0.3, 
1.0.4, 1.0.5, 1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5)

Or:

#12 108.3 ERROR: Could not find a version that satisfies the requirement numpy==1.18.5 (from versions: 1.3.0, 1.4.1, 
1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.2, 1.7.0, 1.7.1, 1.7.2, 1.8.0, 1.8.1, 1.8.2, 1.9.0, 1.9.1, 1.9.2, 1.9.3, 1.10.0.post2, 
1.10.1, 1.10.2, 1.10.4, 1.11.0, 1.11.1, 1.11.2, 1.11.3, 1.12.0, 1.12.1, 1.13.0rc1, 1.13.0rc2, 1.13.0, 1.13.1, 1.13.3, 
1.14.0rc1, 1.14.0, 1.14.1, 1.14.2, 1.14.3, 1.14.4, 1.14.5, 1.14.6, 1.15.0rc1, 1.15.0rc2, 1.15.0, 1.15.1, 1.15.2, 1.15.3, 
1.15.4, 1.16.0rc1, 1.16.0rc2, 1.16.0, 1.16.1, 1.16.2, 1.16.3, 1.16.4, 1.16.5, 1.16.6, 1.17.0rc1, 1.17.0rc2, 1.17.0, 
1.17.1, 1.17.2, 1.17.3, 1.17.4, 1.17.5, 1.18.0rc1, 1.18.0, 1.18.1, 1.18.2, 1.18.3, 1.18.4, 1.18.5, 1.19.0rc1, 
1.19.0rc2, 1.19.0, 1.19.1, 1.19.2, 1.19.3, 1.19.4, 1.19.5)
#12 108.3 ERROR: No matching distribution found for numpy==1.18.5

Current requirements.txt after rolling back some packages, but which is still not finding some modules:

Brotli==1.0.9
dash==2.0.0
dash-bootstrap-components==0.13.1
dash-core-components==2.0.0
dash-html-components==2.0.0
dash-table==5.0.0
Flask==2.0.1
Flask-Compress==1.10.1
itsdangerous==2.0.1
Jinja2==3.0.2
MarkupSafe==1.1.1
numpy==1.17.2
pandas==1.0.5
plotly==5.3.1
python-dateutil==2.8.2
pytz==2021.3
six==1.16.0
tenacity==8.0.1
Werkzeug==2.0.2

Dockerfile:

ARG APP_IMAGE=python:3.6.1-alpine

FROM $APP_IMAGE AS base

FROM base as builder

##test these out

RUN mkdir /install
WORKDIR /install

COPY requirements.txt /requirements.txt

# RUN pip install flask==2.0.0 ###I've tried running pip install of the packages here, which worked but I still kept hitting the same error for each package
# RUN pip install MarkupSafe==2.0.1
RUN pip install --upgrade pip
RUN python3 -m pip install -r /requirements.txt

FROM base
ENV FLASK_APP index.py
WORKDIR /project
COPY --from=builder /install /usr/local
ADD . /project


ENTRYPOINT ["python3", "flask", "run", "--host=0.0.0.0"]

File structure:

-apps
   -main.py
-assets
-env
-app.py
-data.csv
-Dockerfile
-index.py #entry point to the application
-requirements.txt

CodePudding user response:

try using another python instance (this is a python version issue, python 3.6 is not compatible with this requirements)

i think python3.8 will satisfy this requirements

CodePudding user response:

Alpine versions of Docker images are the most compact images of the software that you're trying to use. It's a Docker image that doesn't have several Linux libraries and modules that packages depends to.

If you are worried with the size of your Docker image and have storage requirements to follow, try to use the Python slim image. It's smaller than the standard version but containing several dependencies that Alpine doesn't.

  • Related