13

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,587
  • 1
  • 23
  • 36
Mounarajan
  • 1,287
  • 4
  • 20
  • 39

5 Answers5

17

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
  • 19,629
  • 14
  • 39
  • 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
  • 195
  • 3
  • 8
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
  • 119
  • 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.

Dan
  • 9
  • 1
  • 3