How to fix Python 3 ModuleNotFoundError: No module named 'urlparse'

Problem:

While trying to import�urlparse in Python 3 using

import_urlparse_error.py
import urlparse
import_urlparse_error.py
import urlparse

you see the following error message:

example.txt
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [29], in <cell line: 1>()
----> 1 import urlparse

ModuleNotFoundError: No module named 'urlparse'
traceback.txt
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Input In [29], in <cell line: 1>()
----> 1 import urlparse

ModuleNotFoundError: No module named 'urlparse'

Solution

In Python 3, urlparse has been renamed to urllib.urlparse. In order to import it, use this line instead:

example.py
from urllib.parse import urlparse
fix_import.py
from urllib.parse import urlparse

 


Check out similar posts by category: Python