Python 导入错误:没有名为请求的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24652074/
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
ImportError: No module named request
提问by Mulagala
I am trying to install python SpeechRecognition
on my machine.When i am trying to install the package as pip install SpeechRecognition
. I am getting the following error.
我正在尝试SpeechRecognition
在我的机器上安装 python 。当我尝试将软件包安装为pip install SpeechRecognition
. 我收到以下错误。
import json, urllib.request
ImportError: No module named request
And then i referred and installed requests as pip install requests
i am i am getting Requirement already satisfied
.But still i am unable to install SpeechRecognition
.Please let me know what mistake i am doing.Thanks in advance
然后我提到并安装了请求,因为pip install requests
我得到了Requirement already satisfied
。但我仍然无法安装SpeechRecognition
。请让我知道我在做什么错误。提前谢谢
采纳答案by Martijn Pieters
The SpeechRecognition
library requires Python 3.3 or up:
该SpeechRecognition
库需要 Python 3.3 或更高版本:
Requirements
[...]
The first software requirement is Python 3.3 or better. This is required to use the library.
要求
[...]
第一个软件要求是 Python 3.3 或更高版本。这是使用库所必需的。
and from the Trove classifiers:
来自 Trove 分类器:
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4
编程语言:: Python
编程语言:: Python :: 3
编程语言:: Python :: 3.3
编程语言:: Python :: 3.4
The urllib.request
moduleis part of the Python 3 standard library; in Python 2 you'd use urllib2
here.
该urllib.request
模块是 Python 3 标准库的一部分;在 Python 2 中你会urllib2
在这里使用。
回答by Zzmilanzz Zzmadubashazz
You can do that using Python 2.
您可以使用 Python 2 做到这一点。
- Remove
request
- Make that line:
from urllib2 import urlopen
- 消除
request
- 做那行:
from urllib2 import urlopen
You cannot have request
in Python 2, you need to have Python 3 or above.
你不能request
在 Python 2 中拥有,你需要拥有 Python 3 或更高版本。
回答by Alexx Roche
from @Zzmilanzz's answer I used
来自@Zzmilanzz的回答我用过
try: #python3
from urllib.request import urlopen
except: #python2
from urllib2 import urlopen