【发布时间】: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