Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3.2 Unable to import urllib2 (ImportError: No module named urllib2) [duplicate]

I am using Windows, and I get the error:

ImportError: No module named urllib2 

I think this is the solution for Linux. But how to set this in Windows?

I am using Python 3.2 and I am not able see urllib2 there in the LiB folder.

like image 661
Varada Avatar asked Jul 06 '11 10:07

Varada


People also ask

How do I import urllib2 into Python 3?

import urllib2 response = urllib2. urlopen('https://www.pythonforbeginners.com/') print response.info() html = response. read() # do something response. close() # best practice to close the file Note: you can also use an URL starting with "ftp:", "file:", etc.).

How do I fix No module named urllib2?

The Python "ModuleNotFoundError: No module named 'urllib2'" occurs because the urllib2 module has been split into urllib. request and urllib. response in Python 3. To solve the error, import the module as from urllib.

Can I use urllib2 in python3?

NOTE: urllib2 is no longer available in Python 3 You can get more idea about urllib.

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.


1 Answers

In python 3 urllib2 was merged into urllib. See also another Stack Overflow question and the urllib PEP 3108.

To make Python 2 code work in Python 3:

try:     import urllib.request as urllib2 except ImportError:     import urllib2 
like image 116
newbie Avatar answered Sep 28 '22 20:09

newbie