【问题标题】:Unable to locate package python3-pip in Dockerfile while having Universal Repos enabled启用 Universal Repos 时无法在 Dockerfile 中找到包 python3-pip
【发布时间】:2021-12-06 07:06:49
【问题描述】:

我正在尝试安装 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 之类的其他东西。 我该如何解决这个错误?为什么会这样?

【问题讨论】:

    标签: python docker ubuntu pip dockerfile


    【解决方案1】:

    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 版本,操作系统提供的工具没有卸载(这是一个 pip 功能)。

    无论如何,这个与你的更相似的 dockefile 也可以工作:

    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 配置的新软件包列表。这是我认为的问题的根本原因。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-27
      • 2019-01-16
      相关资源
      最近更新 更多