Rudziankoŭ
Rudziankoŭ

Reputation: 11251

Can not solve ImportError: No module named request

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 Python 2 shell:

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

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

Upvotes: 2

Views: 13545

Answers (3)

falsetru
falsetru

Reputation: 369074

  • urllib.requests module is available in Python 3.x. In Python 2.x, it's urllib module
  • You installed the third-party library requests, but you are trying to import a standard module.

Just you import requests.

Upvotes: 2

Selcuk
Selcuk

Reputation: 59219

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.

Upvotes: 6

SAC
SAC

Reputation: 1

What worked for me was to install python-pip with this command:

sudo apt install python-pip

then I update it with this command

pip install --upgrade pip

Upvotes: 0

Related Questions