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
from urllib import request
? – Joeyjoffreurllib.py
and it is your problem.import urllib
first tries to load fileurllib.py
in local folder and it loads your file instead expected module.. – Hemelytron