如何解決requests,已經(jīng)安裝卻無(wú)法import問(wèn)題
requests已經(jīng)安裝卻無(wú)法import
已經(jīng)pip install requests,后面在pycharm里卻無(wú)法import requests,
已經(jīng)排除不是環(huán)境變量配置問(wèn)題
在python console里面import requests,
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\PyCharm\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'requests'
報(bào)上面這個(gè)錯(cuò)誤。
后面百度到,可以在pycharm里面直接下載安裝需要的庫(kù),不用每次在cmd里面區(qū)pip install ***
方法:
點(diǎn)擊File->settings ->Project Interpreter ,點(diǎn)擊右方的+號(hào),在搜索欄搜索requests,點(diǎn)擊安裝,等待安裝完畢即可。
Python之Request庫(kù)的安裝、安裝卻無(wú)法import、"You should consider upgrading via the 'python -m pip....."
方法一:pip install requests
我在安裝的時(shí)候出現(xiàn)了,**“You should consider upgrading via the ‘python -m pip install --upgrade pip’ command.”**的情況。
我當(dāng)時(shí)跟著打來(lái)著,結(jié)果報(bào)錯(cuò)了。應(yīng)該是 ‘-’ 輸入有誤,建議直接復(fù)制
終于顯示了:Successfully installed pip
不放心的可以檢查一下。
輸入:pip show pip
方法二
點(diǎn)擊File->settings ->Project Interpreter ,點(diǎn)擊右方的+號(hào),在搜索欄搜索requests,點(diǎn)擊安裝。
安裝卻無(wú)法import
我是用方法一安裝的,安裝成功后,用IDLE檢查,import requests成功了,但是回到pycharm里import requests卻報(bào)錯(cuò)。于是直接在pycham里使用方法二安裝,就成功了。
檢查安裝是否成功
>>> import requests >>> r = requests.get("http://www.baidu.com") >>> print(r.status_code) 200 >>> r.text '<!DOCTYPE html>\r\n<!--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>?\x99??o|??\x80??\x8b??\x8c??\xa0?°±?\x9f¥é\x81\x93</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class=head_wrapper> <div class=s_form> <div class=s_form_wrapper> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class=fm> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class=s_ipt value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=?\x99??o|??\x80??\x8b class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class=mnav>?\x96°é\x97?</a> <a href=http://www.hao123.com name=tj_trhao123 class=mnav>hao123</a> <a href=http://map.baidu.com name=tj_trmap class=mnav>?\x9c°?\x9b?</a> <a href=http://v.baidu.com name=tj_trvideo class=mnav>è§\x86é¢\x91</a> <a href=http://tieba.baidu.com name=tj_trtieba class=mnav>è′′?\x90§</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class=lb>?\x99???\x95</a> </noscript> <script>document.write(\'<a + encodeURIComponent(window.location.href+ (window.location.search === " rel="external nofollow" " ? "?" : "&")+ "bdorz_come=1")+ \'" name="tj_login" class="lb">?\x99???\x95</a>\');</script> <a href=//www.baidu.com/more/ name=tj_briicon class=bri style="display: block;">?\x9b′?¤\x9a?o§?\x93\x81</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>?\x853?o\x8e?\x99??o|</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>????\x94¨?\x99??o|?\x89\x8d??\x85èˉ?</a> <a href=http://jianyi.baidu.com/ class=cp-feedback>?\x84\x8fè§\x81?\x8f\x8dé|\x88</a> ?o?ICPèˉ\x81030173?\x8f· <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>\r\n'
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python 實(shí)現(xiàn)遙感影像波段組合的示例代碼
這篇文章主要介紹了Python 實(shí)現(xiàn)遙感影像波段組合的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08基于TensorBoard中g(shù)raph模塊圖結(jié)構(gòu)分析
今天小編就為大家分享一篇基于TensorBoard中g(shù)raph模塊圖結(jié)構(gòu)分析,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-02-02python中三種高階函數(shù)(map,reduce,filter)詳解
在Python中,函數(shù)其實(shí)也是一種數(shù)據(jù)類型,今天重點(diǎn)給大家介紹python中三種高階函數(shù)(map,reduce,filter)的相關(guān)知識(shí),感興趣的朋友一起看看吧2021-10-10用python基于appium模塊開發(fā)一個(gè)自動(dòng)收取能量的小助手
大家都有了解過(guò)螞蟻森林吧,本篇文章帶給你自動(dòng)收取螞蟻森林能量的思路與方法,基于appium模塊開發(fā)一個(gè)自動(dòng)收取能量的小助手,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的價(jià)值2021-09-09Python中print()函數(shù)使用實(shí)例詳解
Python的print()函數(shù)可以打印輸出,常用來(lái)將內(nèi)容打印到控制臺(tái),print()是python中最常見(jiàn)的一個(gè)函數(shù),本文就通過(guò)一些實(shí)例來(lái)給大家講講如何使用print()函數(shù),需要的朋友可以參考下2023-07-07Python實(shí)現(xiàn)九宮格式的朋友圈功能內(nèi)附“馬云”朋友圈
PIL(Python Imaging Library)是一個(gè)非常強(qiáng)大的Python庫(kù),但是它支持Python2.X, 在Python3中則使用的是Pillow庫(kù),它是從PIL中fork出來(lái)的一個(gè)分支。這篇文章主要介紹了用Python搞定九宮格式的朋友圈功能內(nèi)附“馬云”朋友圈 ,需要的朋友可以參考下2019-05-05