gpt4 book ai didi

python - 启用 Universal Repos 时无法在 Dockerfile 中找到包 python3-pip

转载 作者:行者123 更新时间:2023-12-04 19:27:35 24 4
gpt4 key购买 nike

我正在尝试安装 python3 和 pip。
所以,我有一个 dockerfile
(我也尝试过 ubuntu:20.04)-
(注意——我已经把 Dockerfile 缩短了,完整的 dockerfile 你可以看到 here )

FROM ubuntu:latest 

WORKDIR /app
COPY . /app
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN add-apt-repository universe

ENV PYTHONUNBUFFERED=1
RUN apt install -y python3
RUN apt-get -y install python3-pip
RUN pip install --no-cache --upgrade pip setuptools
但它总是给我错误-
 ---> Running in ba9f299b852b
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package python3-pip
The command '/bin/sh -c apt-get -y install python3-pip' returned a non-zero code: 100
虽然在错误中找到更多信息,但我发现虽然添加了通用存储库,但没有安装 python3-pip,而其他的东西,如 python3-sip安装好了。
我该如何解决这个错误,为什么会发生?

最佳答案

software-properties-common 元包安装了一堆在 docker 镜像中不需要的软件,使其体积非常大。
这个更简单的 Dockerfile 为我完成了这项工作。

FROM ubuntu:latest

WORKDIR /app
#COPY . /app
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends --quiet \
python3 \
python3-pip \
&& apt-get clean all

RUN pip install --no-cache --upgrade pip setuptools

RUN pip --version # just for test
输出:
STEP 1/5: FROM ubuntu:latest
STEP 2/5: WORKDIR /app
--> Using cache 9f1d34a70ba9e13074601d16456fda97b2de87a0be3b18ddc6963fb65aaee096
--> 9f1d34a70ba
STEP 3/5: RUN apt-get update && apt-get install --assume-yes --no-install-recommends --quiet python3 python3-pip && apt-get clean all
[...]
STEP 4/5: RUN pip install --no-cache --upgrade pip setuptools
Collecting pip
Downloading pip-21.3-py3-none-any.whl (1.7 MB)
Collecting setuptools
Downloading setuptools-58.2.0-py3-none-any.whl (946 kB)
Installing collected packages: pip, setuptools
Attempting uninstall: pip
Found existing installation: pip 20.0.2
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'pip'. No files were found to uninstall.
Attempting uninstall: setuptools
Found existing installation: setuptools 45.2.0
Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'setuptools'. No files were found to uninstall.
Successfully installed pip-21.3 setuptools-58.2.0
STEP 5/5: RUN pip --version
pip 21.3 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
COMMIT staskoverflow-ubuntu
--> 2498ddc1767
Successfully tagged localhost/staskoverflow-ubuntu:latest
2498ddc17672584d2dd38bf23ae63521d9adb43465cf8c7b415c33dc2aa0aa01
工具 pip 已更新到 21.3 版本,并且未卸载 OS 提供的工具(这是一个 pip 功能)。
无论如何,这个与你的更相似的 dokefile 也可以:
RUN apt-get update \
&& apt-get install --assume-yes --no-install-recommends --quiet \
software-properties-common \
&& add-apt-repository universe \
&& apt-get update \
&& apt-get install --assume-yes --no-install-recommends --quiet \
python3 \
python3-pip \
&& apt-get clean all

RUN pip install --no-cache --upgrade pip setuptools
添加 universe 存储库后,您应该再次运行 apt-get update 以检索具有新 apt 配置的新包列表。这是我认为问题的根本原因。

关于python - 启用 Universal Repos 时无法在 Dockerfile 中找到包 python3-pip,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69629412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com