Tag Archives: The import urllib2 failure

PIP install urlib2 failed

PIP Install Urllib2 prompts that the package cannot be found:

Note
The urllib2 module has been split across several modules inPython 3 named urllib.request and urllib.error.The 2to3 tool will automatically adapt imports when convertingyour sources to Python 3.

The urllib2 toolkit in Pyhton2 is split into urllib.request and urllib.error in Python3. This results in no package being found and no way to install.
So install urllib.request and install urllib.error are required, and then change the import urllib2 to import urllib.request and import urllib.error.
At the same time, the method function in the code also needs to be modified. Basically, urllib2.xxx is changed to urllib.request-xxx.
Official: https://docs.python.org/2/library/urllib2.html.