Python 3.6 导入请求
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43727362/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 3.6 import requests
提问by Avi Teller
Hi im pretty new to python and im following some tutorials online. im using the latest version of python 3.6 when i try and import requests or bs4 is says
嗨,我对 python 很陌生,我在网上学习了一些教程。当我尝试导入请求或 bs4 时,我使用的是最新版本的 python 3.6
ModuleNotFoundError, No module named 'requests'
ModuleNotFoundError,没有名为“请求”的模块
although it is installed i can see it in site packages i used pip to install whatever i seem to do it doesnt seem to be able to find it
虽然它已安装,但我可以在站点包中看到它,但我使用 pip 安装了我似乎在做的任何事情,但似乎无法找到它
here is the code
这是代码
import requests
from bs4 import BeautifulSoup
import operator
def start(url):
word_list = []
source_code = requests.get(url).text
soup = BeautifulSoup(source_code)
for post_text in soup.findAll('div'):
content = post_text.string
words = content.lower().split()
for each_word in words:
print(each_word)
word_list.append(each_word)
start('http://localhost/budget_app/dashboard.php')
this is the error
这是错误
ModuleNotFoundError, No module named 'requests'
回答by Rahul Bagal
Run following command on your virtual environment:
在您的虚拟环境中运行以下命令:
sudo pip install requests
回答by Ravi Ranjan
If your facing issue with proxy setting then run below command:
如果您遇到代理设置问题,请运行以下命令:
pip install requests --proxy http://<username>:password<password>@<IP>:<port>
--proxy [user:passwd@]proxy.server:port.
回答by gautam
Run following command if you have more than one python3.x
如果您有多个 python3.x,请运行以下命令
python3.6 -m pip install requests
回答by Jesus Leyva
I was having the same issue. Despite having the requests packages appeared as installed when I would run the pip install requests
and the pip3 install requests
. The package would also show as present when running the pip freeze command.
我遇到了同样的问题。尽管有出现作为安装的时候我会运行的要求包pip install requests
和pip3 install requests
。运行 pip freeze 命令时,该包也会显示为存在。
I used the file explorer window to find the location of the library and manually copy and paste the package files from the site-package
folder and into it parent Lib
directory.
我使用文件资源管理器窗口来查找库的位置,并手动将包文件从site-package
文件夹复制并粘贴到其父Lib
目录中。
I hope this helps.
我希望这有帮助。