installing urllib in Python3.6

Mohamed Mahdi picture Mohamed Mahdi · Dec 9, 2017 · Viewed 108.3k times · Source

I would like to import urllib to use the function 'request'. However, I encountered an error when trying to do so. I tried pip install urllib but still had the same error. I am using Python 3.6. Really appreciate any help.

i do import urllib.request using this code:

import urllib.request, urllib.parse, urllib.error 
fhand = urllib.request.urlopen('data.pr4e.org/romeo.txt') 
counts = dict()
for line in fhand: 
    words = line.decode().split() 
for word in words: 
    counts[word] = counts.get(word, 0) + 1 
print(counts) 

but it gives me this error: ModuleNotFoundError: No Module named 'urllib.parse'; 'urllib' is not a package

here is a screenshot for the error

Answer

Xero Smith picture Xero Smith · Dec 9, 2017

urllib is a standard library, you do not have to install it. Simply import urllib