重要错误:没有名为reques的模块

2024-06-02 05:08:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在我的机器上安装python SpeechRecognition。当我试图将包安装为pip install SpeechRecognition时。我得到以下错误。

import json, urllib.request

ImportError: No module named request

然后我把安装请求称为pip install requests我得到了Requirement already satisfied。但是我仍然无法安装SpeechRecognition。请让我知道我犯了什么错误。提前谢谢


Tags: installpipnoimport机器jsonrequest错误
3条回答

SpeechRecognitionrequires Python 3.3 or up

Requirements

[...]

The first software requirement is Python 3.3 or better. This is required to use the library.

从Trove分类器:

Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.3
Programming Language :: Python :: 3.4

^{} module是Python 3标准库的一部分;在Python 2中,您可以在这里使用urllib2

从我用的@Zzmilanzz的答案

try: #python3
    from urllib.request import urlopen
except: #python2
    from urllib2 import urlopen

您可以使用Python 2来实现这一点。

  1. 删除request
  2. 做那行:from urllib2 import urlopen

在Python 2中不能有request,需要有Python 3或更高版本。

相关问题 更多 >