How can I import urlparse in python-3?

PythonPython 3.xImportImporterrorUrlparse

Python Problem Overview


I would like to use urlparse. But python3.4.1 is not finding the module.

I do import urlparse, but it gives me this error

importError: no 'module' named ulrparse

Python Solutions


Solution 1 - Python

The urlparse in Python 2.7.11 was renamed to urllib.parse in Python 3. So, if you have a code such from urlparse import urljoin, I suggest you change it to from urllib.parse import urljoin

Solution 2 - Python

As noted in urlparse's documentation:

> Note The urlparse module is renamed to urllib.parse in Python 3. The 2to3 tool will automatically adapt imports when converting your sources to Python 3.

I.e., just use urllib.parse instead:

import urllib.parse

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMohamed MahdiView Question on Stackoverflow
Solution 1 - PythonAbhijitView Answer on Stackoverflow
Solution 2 - PythonMureinikView Answer on Stackoverflow