簡體   English   中英

為什么 Docker build 很難找到這么多 Python 模塊?

[英]Why does Docker build struggle to locate so many Python modules?

我在 docker 構建期間一直看到錯誤消息,在 docker 嘗試安裝我的 requirements.txt 文件的部分,該文件顯示Module Not Found 但是,它說找不到的模塊版本有一半在可用版本列表中。

我一直在嘗試舊版本,最終我會找到一個有效的版本,但同樣的事情會發生在下一個包上。 嘗試構建一個肯定不正確的容器需要花費數小時。 我假設這可能與包可能不會在容器的不同層之間傳遞有關,但我是 Docker 的新手,所以不知道這是否是問題或如何解決它。

我正在使用 WSL2 (Ubuntu 20.04) 在 Python 中構建一個燒瓶應用程序(從技術上講,它是一個 Plotly Dash 應用程序,但我讀過它的工作原理與燒瓶相同)。 我有一台 Windows 10 機器,我確保 Docker 設置為與 WSL2 和 Ubuntu 兼容。 我已經粘貼了我在下面遇到的許多錯誤中的一些,以及我當前的 requirements.txt、Dockerfile 和文件結構。

我想知道如何防止此消息不斷出現以及如何知道哪個包與 Docker 兼容? 任何幫助,將不勝感激。

我看到的一些錯誤消息是:

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

或者:

#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)

或者:

#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

回滾一些包后的當前requirements.txt,但仍然沒有找到一些模塊:

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"]

文件結構:

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

嘗試使用另一個 python 實例(這是一個 python 版本問題,python 3.6 與此要求不兼容)

我認為python3.8會滿足這個要求

Docker 鏡像的 Alpine 版本是您嘗試使用的軟件的最緊湊的鏡像。 它是一個 Docker 鏡像,它沒有幾個包依賴的 Linux 庫和模塊。

如果您擔心 Docker 鏡像的大小並有存儲要求,請嘗試使用Python slim 鏡像 它比標准版本小,但包含幾個 Alpine 沒有的依賴項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM