I’m running Python 3.5.1 for Mac. I want to use
urllib2 module. I tried installing it but I was told that it’s been split into
urllib.error for Python 3.
My command (running from the framework bin directory for now because it’s not in my path):
sudo ./pip3 install urllib.request
Could not find a version that satisfies the requirement urllib.request (from versions: ) No matching distribution found for urllib.request
I got the same error before when I tried to install
urllib2 in one fell swoop.
WARNING: Security researches have found several poisoned packages on PyPI, including a package named
urllib, which will ‘phone home’ when installed. If you used
pip install urllibsome time after June 2017, remove that package as soon as possible.
You can’t, and you don’t 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 don’t need to install it.
If you are following a tutorial that tells you to use
urllib2 then you’ll find you’ll 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. You’ll find
urllib2 comes with that version.
Alternatively, install the
requests library for a higher-level and easier to use API. It’ll 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.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
In Python 3,
urllib2was replaced by two in-built modules named
Adapted from source
So replace this:
import urllib.request as urllib2