主页 > 经验 >

批量离线下载python项目依赖包

2021-10-12 19:51     编辑:小编    点击: A+

专题:
【导读】
Linux服务器中批量离线下载python项目依赖包 由于项目需要,因此总结相关的方法提取python项目的依赖包,为离线环境所使用. 作者:lizhonglin github: https://github.com/Leezhonglin/ blog: https://leezho

Linux服务器中批量离线下载python项目依赖包

由于项目需要,因此总结相关的方法提取python项目的依赖包,为离线环境所使用.

作者:lizhonglin github:
https://github.com/Leezhonglin/ blog: https://leezhonglin.github.io

1.首先我们使用pip自带的命令把自己项目中的依赖导出到requirements.txt文件中去.

pip freeze > requirements.txt

2.创建自己存放下载的安装包的路径

mkdir
/tmp/outline_requirements_packages
(路径自定义) 1 3.使用个国内源下载项目依赖包,通过-i 可以替换国内源,附地址如下:

清华:https://pypi.tuna.tsinghua.edu.cn/simple

阿里云:http://mirrors.aliyun.com/pypi/simple/

中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/

华中理工大学:http://pypi.hustunique.com/

山东理工大学:http://pypi.sdutlinux.org/

豆瓣:http://pypi.douban.com/simple/
pip download -d /tmp/outline_requirements_packages -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

4.拷贝下载好的依赖包到离线服务器的路径中去,例如我们拷贝到 /tmp路径中,然后我们进入/tmp目录中.

pip install --no-index --find-links=/tmp/outline_requirements_packages -r requirements.txt

如果是wheel文件请执行:

pip wheel -w /tmp/outline_requirements_packages -r requirements.txt

如果是windows方法一样,只需要把对应的目录替换成windows的目录就行。

我要投稿

分享到:

相关文章