Need to install urllib2 for Python 3.5.1
Need to install urllib2 for Python 3.5.1
WARNING: Security researches have found several poisoned packages on PyPI, including a package named
urllib
, which will phone home when installed. If you usedpip install urllib
some time after June 2017, remove that package as soon as possible.
You cant, and you dont need to.
urllib2
is the name of the library included in Python 2. You can use the urllib.request
library included with Python 3, instead. The urllib.request
library works the same way urllib2
works in Python 2. Because it is already included you dont need to install it.
If you are following a tutorial that tells you to use urllib2
then youll find youll run into more issues. Your tutorial was written for Python 2, not Python 3. Find a different tutorial, or install Python 2.7 and continue your tutorial on that version. Youll find urllib2
comes with that version.
Alternatively, install the requests
library for a higher-level and easier to use API. Itll work on both Python 2 and 3.
Acording to the docs:
Note The urllib2 module has been split across several modules in Python 3 named
urllib.request
andurllib.error
. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.
So it appears that it is impossible to do what you want but you can use appropriate python3 functions from urllib.request
.
Need to install urllib2 for Python 3.5.1
In Python 3,
urllib2
was replaced by two in-built modules namedurllib.request
andurllib.error
Adapted from source
So replace this:
import urllib2
With this:
import urllib.request as urllib2