W3docs

Import error: No module name urllib2

It looks like you are trying to import the urllib2 module, which is not available in Python 3.

It looks like you are trying to import the urllib2 module, which is not available in Python 3. In Python 3, the urllib2 module has been merged with the urllib module and is no longer available as a separate module.

To fix the import error, you should change your import statement to import urllib. You will also need to update any code that uses functions from urllib2 to use the equivalent functions from the urllib module.

For example, the following code will import the urlopen function from urllib2 in Python 2:

Import urllib2 module in Python2

import urllib2
response = urllib2.urlopen('http://www.example.com')

In Python 3, you can use the following code to import the urlopen function from urllib:

Import urllib module in Python3

import urllib
response = urllib.request.urlopen('http://www.example.com')

You can find more information about the changes to the urllib module in Python 3 in the Python documentation.