MacOS 解決“import requests No module named requests”
阿新 • • 發佈:2018-07-16
pri .py for doctype imp spell module mac os set MacOS 解決“import requests No module named requests”
- 系統信息
sw_vers ProductName: Mac OS X ProductVersion: 10.12.2 BuildVersion: 16C67
- 測試腳本
#內容如下: cat test.py #!/usr/bin/env python import requests baidu_request = requests.get(‘http://www.baidu.com‘) print baidu_request.text
- 報錯信息
#執行腳本 python ./test.py #報錯信息如下: “import requests No module named requests”
- 解決方法
原因: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><。。。。。
MacOS 解決“import requests No module named requests”