Can not solve ImportError: No module named request

13,162

Solution 1

You are confusing the 3rd party module named requests with the Python 3's built-in urllib.request. You can use

import requests

both with Python 2 and 3. However, you can use

from urllib.request import urlopen

only with Python 3.

Solution 2

Why dont you just import requests?

Share:
13,162
Rudziankoŭ
Author by

Rudziankoŭ

Nice to meet you!

Updated on July 16, 2022

Comments

  • Rudziankoŭ
    Rudziankoŭ almost 2 years

    I have read this question

    1) I installed pip and I executed

     pip install requests
    

    and got

    Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/dist-packages/requests-2.9.1-py2.7.egg
    Cleaning up...
    

    2) I started my python2 shell:

    >>> from urllib.request import urlopen
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ImportError: No module named request
    

    Why I am still catching this exception? What I am doing wrong?