MacOS 解决“import requests No module named requests”

作者: gu_lao_rou-p 分类: Python 发布时间: 2020-09-12 15:21

MacOS 解决“import requests No module named requests”

  1. 系统信息
sw_vers
ProductName:    Mac OS X
ProductVersion: 10.12.2
BuildVersion:   16C67

2.测试脚本

#内容如下:
cat test.py 
#!/usr/bin/env python
import requests
baidu_request = requests.get('http://www.baidu.com')
print baidu_request.text

3.报错信息

#执行脚本
python ./test.py
#报错信息如下:
“import requests No module named requests”
4.解决方法
原因:mac osx上默认没有安装requests库
#安装pip
sudo easy_install pip
如报错:Download error on https://pypi.python.org/simple/pip/: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590) -- Some packages may not be found!
Couldn't find index page for 'pip' (maybe misspelled?)
#处理pip安装报错
curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py
sudo python get-pip.py
#安装requests库
sudo pip install requests
#ok现在可以正常执行test.py
python test.py 
<!DOCTYPE html>
<!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>Title</title></head><body></body></html>

Warning: Undefined variable $aria_req in /www/wwwroot/l.lvovl.cn/wp-content/themes/JieStyle-Two-master/comments.php on line 26

Warning: Undefined variable $aria_req in /www/wwwroot/l.lvovl.cn/wp-content/themes/JieStyle-Two-master/comments.php on line 27

Warning: Undefined variable $aria_req in /www/wwwroot/l.lvovl.cn/wp-content/themes/JieStyle-Two-master/comments.php on line 28
标签云