ImportError: No module named request

百般思念 提交于 2019-11-27 00:51:04

问题


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.

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


回答1:


The SpeechRecognition library requires Python 3.3 or up:

Requirements

[...]

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

and from the Trove classifiers:

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

The urllib.request module is part of the Python 3 standard library; in Python 2 you'd use urllib2 here.




回答2:


You can do that using Python 2.

  1. Remove request
  2. Make that line: from urllib2 import urlopen

You cannot have request in Python 2, you need to have Python 3 or above.




回答3:


from @Zzmilanzz's answer I used

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


来源:https://stackoverflow.com/questions/24652074/importerror-no-module-named-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!