python 离线依赖包打包&安装

有时候网络不给力,很多依赖包通过pip下载太慢了,可以通过已有的环境导出再导入新环境.

现有环境导出

pip freeze > requestments.txt # 编辑此文件对需要的包进行删减
 
pip download  -r requirements.txt  -d  /tmp/paks/ #下载requirements.txt中包至 /tmp/paks/下

导入新环境

 pip install   --no-index   --find-links=/packs/   pandas 或      
 pip install   --no-index   --find-links=/packs/   -r   requirements.txt (也可能是 --find-link)

1.主机1(虚拟环境激活)pip freeze >requirements.txt 将虚拟环境中安装的Python依赖包记录到文件requirements.txt中。

2.主机1(虚拟环境激活)pip install --download (项目目录)\whls -r requirements.txt 将安装的Python依赖包保存到(项目目录)\whls目录下。

3.主机2 在断网的主机上安装好python3.6

4.主机2 在项目下建立虚拟环境,并激活。同时将whls文件夹和requirements.txt复制粘贴到项目目录下。

5.主机2(虚拟环境激活)pip install --no-index --find-index=(项目目录)\whls -r requirements.txt 在主机2的虚拟环境中安装requirements.txt里的依赖包。

ref
https://blog.csdn.net/chengyikang20/article/details/81060188
https://blog.csdn.net/vevenlcf/article/details/83110204

https://jiasule.v2ex.com/t/309747

猜你喜欢

转载自blog.csdn.net/qq_35608277/article/details/84997649