首页 > 解决方案 > Docker:离线安装python包

问题描述

我想做什么?

使用下载的轮文件安装 requirements.txt 中提到的所有依赖项,即在Docker中离线安装包

我做了什么?

通过遵循这个线程,我设法将我所有的轮子下载到一个 Wheelhouse 文件夹中mkdir wheelhouse && pip download -r requirements.txt -d wheelhouse,并创建了一个压缩的 tarball wheelhouse.tar.gz,其中包含我所有下载.whl的文件以及一个requirements.txt

当我尝试使用 本地(Docker 外部)安装轮子时pip install -r wheelhouse/requirements.txt --no-index --find-links wheelhouse,它可以工作!

但是当我在 Docker 中运行相同的程序时,它不会出现以下错误:

Processing ./wheelhouse/beautifulsoup4-4.8.2-py3-none-any.whl 
ERROR: Could not find a version that satisfies the requirement blis==0.4.1 (from -r ./wheelhouse/requirements.txt (line 2)) (from versions: none)
ERROR: No matching distribution found for blis==0.4.1 (from -r ./wheelhouse/requirements.txt (line 2))

虽然实际上,轮子blis 0.4.1存在于我的驾驶室目录中。

谁能帮我确定为什么它不能在 Docker 上运行并在本地运行?

Dockerfile

FROM python:3

COPY . /app
WORKDIR /app

RUN tar -zxf ./wheelhouse.tar.gz 

RUN pip install -r ./wheelhouse/requirements.txt --no-index --find-links ./wheelhouse

wheelhouse目录截图

C

标签: pythondockerpip

解决方案


推荐阅读