MacOS 解决“import requests No module named requests”
  TEZNKK3IfmPf 2023年11月14日 70 0

MacOS 解决“import requests No module named requests”

  1. 系统信息
sw_vers
ProductName:	Mac OS X
ProductVersion:	10.12.2
BuildVersion:	16C67
  1. 测试脚本
#内容如下:
cat test.py 
#!/usr/bin/env python
import requests
baidu_request = requests.get('http://www.baidu.com')
print baidu_request.text
  1. 报错信息
#执行脚本
python ./test.py
#报错信息如下:
“import requests No module named requests”
  1. 解决方法 原因:mac osx上默认没有安装requests库
#安装pip
sudo easyinstall 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><。。。。。
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

上一篇: Ossim4系统故障处理 下一篇: 谈谈网络编程
  1. 分享:
最后一次编辑于 2023年11月14日 0

暂无评论

TEZNKK3IfmPf