Python3离线安装Requests模块问题
作者:Laycher 时间:2021-05-06 09:58:24
最近运维上需要在测试环境调用http的post请求,实现自动化日切,我看了下我会的编程,也就python能符合我的要求,且简单好操作。但是在实际操作过程遇到了一些问题,其中最大的就是测试环境的机器是外网隔离的,没法连外网进行直接安装部分模块,通过搜索和实践之后,简单说下我的经验。
机器环境
操作系统:Windows Server 2012 x64
python3安装
从 [官网] 下载最新的适合windows 的安装包。
下载下来的python-3.7.4-amd64.exe,直接拷贝到测试环境的机器上,双击安装即可,需要注意的是,最好勾选 AddPython 3.7 to PATH,这样后期直接在cmd窗口中就可以调用python命令了。
requests模块的依赖包检查
在可以上网且已安装python的机器上检查requests模块需要哪些依赖包,要是没有依赖包,直接下载一个直接安装最好。
在CMD命令窗口中输入 pip show requests
C:\Users\Laycher>pip show requests
Name: requests
Version: 2.18.4
Summary: Python HTTP for Humans.
Home-page: http://python-requests.org
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: d:\program files\python3\lib\site-packages
Requires: chardet, urllib3, idna, certifi
Required-by:
发现需要chardet,urllib3,idna,certifi
下载依赖包模块和requests模块
在网站 https://www.lfd.uci.edu/~gohlke/pythonlibs 上找到相应的程序,下载。
certifi-2019.9.11-py2.py3-none-any.whl
chardet-3.0.4-py2.py3-none-any.whl
idna-2.8-py2.py3-none-any.whl
requests-2.22.0-py2.py3-none-any.whl
urllib3-1.25.6-py2.py3-none-any.whl
安装模块
将以上下载的文件传到测试环境。离线装模块。
安装命令为 pip install XXXXX.whl
切记,先安装依赖包,如果直接安装requests,由于有依赖包,还是会去连外网找依赖包。
D:\软件>pip install certifi-2019.9.11-py2.py3-none-any.whl
Processing d:\软件\certifi-2019.9.11-py2.py3-none-any.whl
Installing collected packages: certifi
Successfully installed certifi-2019.9.11
D:\软件>pip install chardet-3.0.4-py2.py3-none-any.whl
Processing d:\软件\chardet-3.0.4-py2.py3-none-any.whl
Installing collected packages: chardet
Successfully installed chardet-3.0.4
D:\软件>pip install idna-2.8-py2.py3-none-any.whl
Processing d:\软件\idna-2.8-py2.py3-none-any.whl
Installing collected packages: idna
Successfully installed idna-2.8
D:\软件>pip install urllib3-1.25.6-py2.py3-none-any.whl
Processing d:\软件\urllib3-1.25.6-py2.py3-none-any.whl
Installing collected packages: urllib3
Successfully installed urllib3-1.25.6
D:\软件>pip install requests-2.22.0-py2.py3-none-any.whl
Processing d:\软件\requests-2.22.0-py2.py3-none-any.whl
Requirement already satisfied: idna in c:\users\administrator\appdata\local\prog
rams\python\python37\lib\site-packages (from requests==2.22.0) (2.8)
Requirement already satisfied: chardet in c:\users\administrator\appdata\local\p
rograms\python\python37\lib\site-packages (from requests==2.22.0) (3.0.4)
Requirement already satisfied: urllib3 in c:\users\administrator\appdata\local\p
rograms\python\python37\lib\site-packages (from requests==2.22.0) (1.25.6)
Requirement already satisfied: certifi in c:\users\administrator\appdata\local\p
rograms\python\python37\lib\site-packages (from requests==2.22.0) (2019.9.11)
Installing collected packages: requests
Successfully installed requests-2.22.0
安装包汇集
我汇集了我这边的安装包,[点此下载 ]
其他办法
网上还有很多其他办法,比如在干净的能上外网的机器上,安装python,然后pip install 安装需要的模块,然后直接把python安装目录直接拷到离线环境中,那就直接可以用了。
还有的是通过命令 pip freeze > requiresment.txt ,生成已经安装的模块信息,然后再下载。具体可以搜索看看。
总结
以上所述是小编给大家介绍的Python3离线安装Requests模块问题,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!
来源:http://laycher.com/python3-offline-install-requests.html
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
asp如何获知页面上的图象的实际尺寸?
PHP attributes()函数讲解
![](https://img.aspxhome.com/file/2023/0/55410_0s.png)
Python强大的自省机制详解
![](https://img.aspxhome.com/file/2023/3/97723_0s.jpg)
python 基本数据类型占用内存空间大小的实例
详解django自定义中间件处理
python数据可视化之条形图画法
![](https://img.aspxhome.com/file/2023/6/98966_0s.jpg)
Python实现自动添加脚本头信息的示例代码
简易的全屏透明遮罩(lightBox)
Django的用户模块与权限系统的示例代码
Python Pandas 修改表格数据类型 DataFrame 列的顺序案例
MYSQL教程:索引和查询优化程序
JavaScript图片放大镜效果
![](https://img.aspxhome.com/file/UploadPic/up/2009101922390143.gif)
Python之web模板应用
phpstorm断点调试方法图文详解
![](https://img.aspxhome.com/file/2023/9/55259_0s.jpg)
Pytorch深度学习addmm()和addmm_()函数用法解析
![](https://img.aspxhome.com/file/2023/2/95252_0s.gif)
SQL查询不重复记录/删除重复记录
Python技巧之四种多线程应用分享
使用Python+wxpy 找出微信里把你删除的好友实例
![](https://img.aspxhome.com/file/2023/9/67779_0s.jpg)
OpenCV图像缩放之cv.resize()函数详解
![](https://img.aspxhome.com/file/2023/7/93817_0s.jpg)