微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

MacOS 解决“import requests No module named requests”

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 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>????o|?????????????°±??¥é??</title><。。。。。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐