哪有什么岁月静好,不过是有人替你负重前行!

python包的多种安装方式(内网)

python官网下载需要安装的包,有两种形式,我们一matplotlib包为例,一种是压缩包(如:matplotlib-3.2.2.tar.gz (40.3 MB)),一种是以whl结尾的文件(matplotlib-3.2.2-cp36-cp36m-manylinux1_x86_64.whl (12.4 MB)),将下载好的数据包传入到内网即可,具体安装步骤如下:

一、通过压缩包进行安装

1、对matplotlib-3.2.2.tar.gz 压缩包进行解压

2、进入到加压后的文件夹所在的路径,执行如下命令:

python setup.py install

 

二、通过whl结尾的文件进行安装

1、进入whl结尾的文件所在的文件夹,执行如下命令:

pip install matplotlib-3.2.2-cp36-cp36m-manylinux1_x86_64.whl 

 

三、批量安装python包

以django项目依赖包为例

外网电脑

激活django项目依赖的python虚拟环境:

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

(venv) C:\files\project\RobotQA>pip freeze >requirements.txt

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

(venv) C:\files\project\RobotQA>pip download -r requirements.txt -d whls

如果出现超时现象,一般是网速有关,可以加上超时时间如下:

(venv) C:\files\project\RobotQA>pip --default-timeout=1000  download -r requirements.txt -d whls

 

内网电脑

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

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

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

(venv) C:\files\project\RobotQA>pip install --no-index --find-links C:\Users\Sean\Desktop\files\whls -r requirements.txt

完成以上步骤即可将django项目依赖的所有包安装完成!!!

  

posted @ 2020-07-16 17:09  迎风而来  阅读(3539)  评论(0编辑  收藏  举报
/*吸附球*/