Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

installing urllib in Python3.6

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

like image 677
Mohamed Mahdi Avatar asked Dec 09 '17 15:12

Mohamed Mahdi


People also ask

Is Urllib built in Python 3?

The urllib module in Python 3 allows you access websites via your program. This opens up as many doors for your programs as the internet opens up for you. urllib in Python 3 is slightly different than urllib2 in Python 2, but they are mostly the same.

How do I import Urlopen into Python 3?

You need to use from urllib. request import urlopen , also I suggest you use the with statement while opening a connection. @BradleyD. Freeman-Bain: you can't have a with -statement without the following block.


1 Answers

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

like image 190
Xero Smith Avatar answered Sep 18 '22 18:09

Xero Smith