一、下载需要的pip包
通过一下两种方式下载:
1、[root@ecs ~]# pip download numpy -d /opt/pip
2、[root@ecs ~]# pip download -d /opt/pip -r requirements.txt ##将要下载的包写入requirements.txt文件
也可以通过一下命令或得系统中已经安装的pip包,并写入到requirements.txt
[root@ecs ~]# pip freeze > requirements.txt
#####举例如下:
[root@ecs ~]# pip download numpy -d /opt/pip
Collecting numpy
Using cached https://files.pythonhosted.org/packages/3a/5f/47e578b3ae79e2624e205445ab77a1848acdaa2929a00eeef6b16eaaeb20/numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl
Saved /opt/pip/numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl
Successfully downloaded numpy
[root@ecs ~]# ll /opt/pip/
total 16612
-rw-r--r-- 1 root root 17008014 Dec 24 16:42 numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl
二、安装离线包
通过两种方式安装
1、pip install --no-index --find-links=/opt/pip numpy ##指定pip包名称
2、pip install --no-index --find-links=/opt/pip -r requirements.txt ##将要安装的包写入requirements.txt文件中
举例如下:
[root@ecs ~]# cat requirements.txt
numpy==1.16.6
[root@ecs ~]# pip install --no-index --find-links=/opt/pip -r requirements.txt
Looking in links: /opt/pip
Processing /opt/pip/numpy-1.16.6-cp27-cp27mu-manylinux1_x86_64.whl
Installing collected packages: numpy
Successfully installed numpy-1.16.6
[root@ecs ~]# pip list | grep numpy
numpy 1.16.6
[root@ecs ~]#
[root@ecs ~]#