导入错误:ImportError:没有名为requests

时间:2017-10-15 05:06:41

标签: python python-2.7 import module urllib

我是python和webscraping的新手。我使用linux mint 18.2和python 2.7.12。 我试图导入并最终使用beautifulsoup执行urllib.request但最终失败到现在为止。我在stackoverflow引用之后安装了请求模块 - sudo apt-get install python-requests。哪个成功了。

所以,请查看我执行的所有试验和错误(到目前为止未成功)并帮助我执行urllib.request。谢谢!

>>> import bs4
>>> pip install urllib
SyntaxError: invalid syntax
>>> import urlihb

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    import urlihb
ImportError: No module named urlihb
>>> import urllib
>>> from urllib.request import urlopen as newreq

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    from urllib.request import urlopen as newreq
ImportError: No module named request
>>> import urllib2
>>> from urllib2.request import urlopen as newreq

Traceback (most recent call last):
  File "<pyshell#6>", line 1, in <module>
    from urllib2.request import urlopen as newreq
ImportError: No module named request
>>> sudo pip install request
SyntaxError: invalid syntax
>>> sudo install request
SyntaxError: invalid syntax
>>> sudp pip install requests
SyntaxError: invalid syntax
>>> sudo pip install requests
SyntaxError: invalid syntax
>>> sudo install requests
SyntaxError: invalid syntax
>>> import urllib2
>>> from urllib2.request import urlopen as newreq

Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    from urllib2.request import urlopen as newreq
ImportError: No module named request
>>> from urllib2.requests import urlopen as newreq

Traceback (most recent call last):
  File "<pyshell#14>", line 1, in <module>
    from urllib2.requests import urlopen as newreq
ImportError: No module named requests
>>> import urllib3.request import urlopen as newreq
SyntaxError: invalid syntax
>>> import urllib2.request

Traceback (most recent call last):
  File "<pyshell#16>", line 1, in <module>
    import urllib2.request
ImportError: No module named request
>>> urllib2.requests

Traceback (most recent call last):
  File "<pyshell#17>", line 1, in <module>
    urllib2.requests
AttributeError: 'module' object has no attribute 'requests'
>>> import urllib2.requests

Traceback (most recent call last):
  File "<pyshell#18>", line 1, in <module>
    import urllib2.requests
ImportError: No module named requests
>>> import urllib2.request

Traceback (most recent call last):
  File "<pyshell#19>", line 1, in <module>
    import urllib2.request
ImportError: No module named request
>>> import urllib.reques

Traceback (most recent call last):
  File "<pyshell#20>", line 1, in <module>
    import urllib.reques
ImportError: No module named reques
>>> import urllib.request

Traceback (most recent call last):
  File "<pyshell#21>", line 1, in <module>
    import urllib.request
ImportError: No module named request
>>> import beautifulsoup

Traceback (most recent call last):
  File "<pyshell#22>", line 1, in <module>
    import beautifulsoup
ImportError: No module named beautifulsoup
>>> import beautifullsoup as bs4

Traceback (most recent call last):
  File "<pyshell#23>", line 1, in <module>
    import beautifullsoup as bs4
ImportError: No module named beautifullsoup
>>> import bs4
>>> import urllib.request

Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    import urllib.request
ImportError: No module named request
>>> import urllib2.request

Traceback (most recent call last):
  File "<pyshell#26>", line 1, in <module>
    import urllib2.request
ImportError: No module named request
>>> import urllib.requests

Traceback (most recent call last):
  File "<pyshell#27>", line 1, in <module>
    import urllib.requests
ImportError: No module named requests
>>> import urllib2.requests

Traceback (most recent call last):
  File "<pyshell#28>", line 1, in <module>
    import urllib2.requests
ImportError: No module named requests
>>> 

1 个答案:

答案 0 :(得分:0)

您只需要:&#34; import urllib.request&#34;

运行&#34; pip install urllib&#34;