Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut] How to Fix Error: No Module Named ‘urlparse’ (Easily)
1
How to Fix Error: No Module Named ‘urlparse’ (Easily)

4/5 – (1 vote)

You may experience the following error message in your Python code when trying to import
Code:
urlparse
:

Code:
ModuleNotFoundError: No module named 'urlparse'

Code:
>>> import urlparse Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> import urlparse ModuleNotFoundError: No module named 'urlparse'

How to fix it and what is the reason this error occurs?

[Image: image-71.png]

This error usually occurs because
Code:
urlparse
has been renamed to
Code:
urllib.parse
. So you need to
Code:
pip install urllib
and then
Code:
import urllib
and call
Code:
urllib.parse
to make it work.

To accomplish this, follow the tutorial outlined next or simply try running this command in your terminal, console, shell, or command line:

Code:
pip install urllib

After that, you can use urllib.parse like so (source):

Code:
from urllib.parse import urlparse urlparse("scheme://netloc/path;parameters?query#fragment") o = urlparse("http://docs.python.org:80/3/library/urllib.parse.html?" "highlight=params#url-parsing") print(o)

Output:

Code:
ParseResult(scheme='http', netloc='docs.python.org:80', path='/3/library/urllib.parse.html', params='', query='highlight=params', fragment='url-parsing')

[Image: 1f30d.png] Recommended Tutorial: How to Install urllib in Python?
Reply

Users browsing this thread:
1 Guest(s)


Forum Jump: