【问题标题】:Running pip inside Docker container - won't install desired version of module在 Docker 容器中运行 pip - 不会安装所需版本的模块
【发布时间】:2022-01-09 20:20:48
【问题描述】:

我正在使用官方的python:3.9-slim Docker 映像,并且我正在尝试在我的 Dockerfile 中使用以下命令安装特定版本的 Python 包:

python3 -m pip --no-cache-dir install --user --upgrade ansible-core~=2.11

此时将在 Docker 容器外部安装 ansible-core 2.11.6 - 这是正确的版本,因为它是最新的 2.11 版本。

但是,我无法让它从我的 Docker 容器中抓取 2.11.x,它只会抓取 2.12.0:

Collecting ansible-core~=2.11
  Downloading ansible-core-2.12.0.tar.gz (7.4 MB)

这里有什么基本的东西我弄错了吗?

【问题讨论】:

  • 为什么不能直接使用== 而不是~= 固定依赖?
  • 也许值得一提你在容器外的python版本。
  • 我不想那么具体并将其绑定到特定的次要补丁版本,但想坚持一个次要版本。容器外已经针对python3.6进行了测试。 2.11.x 版本没有任何限制,这意味着它不能在 python3.9 下安装 - 要求:Python >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, ! =3.3.*, !=3.4.*
  • 这有帮助吗? python3 -m pip --no-cache-dir install --user --upgrade "ansible-core>=2.11,<2.12"
  • 我觉得你需要版本号的最后一段:ansible-core~=2.11.0python.org/dev/peps/pep-0440/#compatible-release

标签: python docker pip dockerfile


【解决方案1】:

我不太明白为什么,但是如果您将版本号的最后一段(2.11.0 而不是 2.11)添加到命令中,它将下载您期望的版本。

【讨论】:

    猜你喜欢
    • 2019-06-01
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 2019-12-23
    • 2015-09-01
    • 2018-01-28
    • 2019-06-25
    • 1970-01-01
    相关资源
    最近更新 更多