如何解決requests,已經(jīng)安裝卻無法import問題
requests已經(jīng)安裝卻無法import
已經(jīng)pip install requests,后面在pycharm里卻無法import requests,
已經(jīng)排除不是環(huá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'
報上面這個錯誤。
后面百度到,可以在pycharm里面直接下載安裝需要的庫,不用每次在cmd里面區(qū)pip install ***
方法:
點(diǎn)擊File->settings ->Project Interpreter ,點(diǎn)擊右方的+號,在搜索欄搜索requests,點(diǎn)擊安裝,等待安裝完畢即可。

Python之Request庫的安裝、安裝卻無法import、"You should consider upgrading via the 'python -m pip....."
方法一:pip install requests
我在安裝的時候出現(xiàn)了,**“You should consider upgrading via the ‘python -m pip install --upgrade pip’ command.”**的情況。
我當(dāng)時跟著打來著,結(jié)果報錯了。應(yīng)該是 ‘-’ 輸入有誤,建議直接復(fù)制
終于顯示了:Successfully installed pip
不放心的可以檢查一下。
輸入:pip show pip

方法二
點(diǎn)擊File->settings ->Project Interpreter ,點(diǎn)擊右方的+號,在搜索欄搜索requests,點(diǎn)擊安裝。

安裝卻無法import
我是用方法一安裝的,安裝成功后,用IDLE檢查,import requests成功了,但是回到pycharm里import requests卻報錯。于是直接在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é)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
基于tkinter中ttk控件的width-height設(shè)置方式
這篇文章主要介紹了基于tkinter中ttk控件的width-height設(shè)置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-05-05
python基于機(jī)器學(xué)習(xí)預(yù)測股票交易信號
近年來,隨著技術(shù)的發(fā)展,機(jī)器學(xué)習(xí)和深度學(xué)習(xí)在金融資產(chǎn)量化研究上的應(yīng)用越來越廣泛和深入。目前,大量數(shù)據(jù)科學(xué)家在Kaggle網(wǎng)站上發(fā)布了使用機(jī)器學(xué)習(xí)/深度學(xué)習(xí)模型對股票、期貨、比特幣等金融資產(chǎn)做預(yù)測和分析的文章。本文就來看看如何用python預(yù)測股票交易信號2021-05-05
python實現(xiàn)學(xué)生信息管理系統(tǒng)源碼
這篇文章主要為大家詳細(xì)介紹了python實現(xiàn)學(xué)生信息管理系統(tǒng)源碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-02-02
用python實現(xiàn)的可以拷貝或剪切一個文件列表中的所有文件
python 實現(xiàn)剪切或是拷貝一個文件列表中的所有文件2009-04-04
使用Python的地理可視化庫進(jìn)行地圖動畫的制作方法
隨著數(shù)據(jù)科學(xué)和可視化的迅速發(fā)展,地圖動畫成為了展示地理數(shù)據(jù)變化的有力工具,Python作為一種強(qiáng)大的編程語言,有著豐富的地理可視化庫,本文將介紹如何使用Python的地理可視化庫來制作地圖動畫,并通過代碼實例來演示,需要的朋友可以參考下2024-05-05
Python使用Matplotlib庫創(chuàng)建3D 圖形和交互式圖形詳解
Matplotlib 是 Python 中最重要的數(shù)據(jù)可視化庫之一,在本文中,我們將深入研究 Matplotlib 的高級特性,特別是如何創(chuàng)建 3D 圖形和交互式圖形,需要的朋友可以參考下2023-07-07

