【问题标题】:pip unable to fetch wheels when inside container在容器内时 pip 无法获取轮子
【发布时间】:2021-10-19 18:26:57
【问题描述】:

当我尝试构建包含通过 pip 安装 Python 模块的映像时,构建容器仅使用源代码分发,因此总是从源代码编译所有模块,这非常烦人...

如何让容器内的 pip 像主机系统一样使用轮子?

从主机系统运行时

# pip3 -V
pip 18.1 from /usr/lib/python3/dist-packages/pip (python 3.7)

# pip3 install numpy
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting numpy
  Using cached https://www.piwheels.org/simple/numpy/numpy-1.21.2-cp37-cp37m-linux_armv7l.whl

当在docker run -it python:3.7 /bin/bash内运行时

# pip3 -V
pip 21.2.4 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)

# pip3 install numpy
Collecting numpy
  Downloading numpy-1.21.2.zip (10.3 MB)

当我在一个没有 shell 的命令中运行所有内容时,它也可以工作

# docker run -it python:3.8 python3 -m pip install -U pip wheel setuptools &&  python3 -m pip install Pillow
Requirement already satisfied: pip in /usr/local/lib/python3.8/site-packages (21.2.4)
Requirement already satisfied: wheel in /usr/local/lib/python3.8/site-packages (0.37.0)
Requirement already satisfied: setuptools in /usr/local/lib/python3.8/site-packages (57.4.0)
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting Pillow
  Downloading https://www.piwheels.org/simple/pillow/Pillow-8.3.1-cp37-cp37m-linux_armv7l.whl (1.3 MB)

我尝试过的事情

  • 以特权身份运行
  • 使用点标志--no-binary=:all:

系统信息:

  • 树莓派 4
  • Linux 5.10.17-v7l+ armv7l GNU/Linux
  • Raspbian GNU/Linux 10(破坏者)
  • ARMv7 处理器版本 3 (v7l)

【问题讨论】:

    标签: docker pip python-wheel


    【解决方案1】:

    请注意,您使用的是https://www.piwheels.org/,它仅为 Raspberry Pi 提供轮子。打开https://www.piwheels.org/simple/numpy/可以看到只有armv6l和armv7l轮子。

    可能在容器中你忘记修改索引url并将其设置为https://www.piwheels.org/simple

    【讨论】:

    • 这个特定的容器在 Raspberry Pi 上运行,所以这应该没问题(Pi 使用 arm7l),但我要手动设置 URL,看看我是否可以让它运行......
    猜你喜欢
    • 2019-10-09
    • 1970-01-01
    • 2022-11-06
    • 2016-02-18
    • 2020-05-15
    • 1970-01-01
    • 2021-07-20
    • 1970-01-01
    • 2014-01-24
    相关资源
    最近更新 更多