no module named urllib.parse (How should I install it?)

javiercruzweb picture javiercruzweb · Mar 31, 2015 · Viewed 168.8k times · Source

I'm trying to run a REST API on CentOS 7, I read urllib.parse is in Python 3 but I'm using Python 2.7.5 so I don't know how to install this module.

I installed all the requirements but still can't run the project.

When I'm looking for a URL I get this (I'm using the browsable interface):

Output:

ImportError at /stamp/
No module named urllib.parse

Answer

Agnaldo Marinho picture Agnaldo Marinho · May 30, 2016

If you need to write code which is Python2 and Python3 compatible you can use the following import

try:
    from urllib.parse import urlparse
except ImportError:
     from urlparse import urlparse