pip内网依赖离线下载和安装

2024-09-05 11:21:19 浏览数 (15)

思路:在外网环境使用pip离线下载(不安装)依赖,然后上传到服务器再进行离线安装

下载:

使用 pip download 命令离线下载 requirements.txt 中列出的所有依赖包,而不安装它们:

代码语言:bash复制
pip3 download --no-cache-dir --dest /path/to/downloaded_packages -r /requirements.txt

参数解释:

--no-cache-dir: 禁用缓存。

--dest /path/to/downloaded_packages: 指定下载包的目标目录。

-r /requirements.txt: 指定包含依赖列表的文件。

安装:

使用 pip install 命令来安装所有依赖

代码语言:basic复制
pip3 install --no-index --find-links=/whls -r /requirements.txt

注意:/requirements.txt中的依赖和/whls 目录中的依赖要对应

参数解释:

--no-index: 禁用从 PyPI 索引中查找包。

--find-links=/whls: 指定查找包的目录。

-r /requirements.txt: 指定你的依赖文件,requirements.txt 中列出的所有包都会被安装

:

0 人点赞