14

Tried installing urllib.request module using below command

sudo pip install urllib.request

but it returned

Downloading/unpacking urllib.request
  Could not find any downloads that satisfy the requirement urllib.request
Cleaning up...
No distributions at all found for urllib.request
Storing debug log for failure in /home/mounarajan/.pip/pip.log

How can I install this module?

shantanoo
  • 3,617
  • 1
  • 24
  • 37
Mounarajan
  • 1,357
  • 5
  • 22
  • 43

5 Answers5

18

urllib.request is only available in python3 branch. See the following post for more info. urllib.request in Python 2.7

Community
  • 1
  • 1
Kozyarchuk
  • 21,049
  • 14
  • 40
  • 46
8

In python3 you must use urllib3 module.

$ pip3 install urllib3

Or if you're using a virtual env:

$ pip install urllib3
Tim Nikitin
  • 325
  • 5
  • 9
6

In python 2 ,you simply use urllib for example

import urllib
htmlfile=urllib.urlopen("your url")
htmltext=htmlfile.read()

in python 3,you need to use urllib.request

import urllib.request
htmlfile=urllib.request.urlopen("your url")
htmltext=htmlfile.read()
3

For Python3 in cmd,

pip install urllib3

Or if you're using a anaconda:

conda install urllib3

Hope, this will help you

user99
  • 157
  • 1
  • 4
0

For future reader (which I believe most of them are python3 users), urllib is already available on Python3 simply import urllib to your code.

Henry Davis
  • 101
  • 1
  • 9