Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 
like image 984
javiercruzweb Avatar asked Mar 31 '15 00:03

javiercruzweb


People also ask

How do I use Urllib parse in Python?

parse — Parse URLs into components in Python. This module provides a standard interface to break Uniform Resource Locator (URL) strings in components or to combine the components back into a URL string. It also has functions to convert a "relative URL" to an absolute URL given a "base URL."

Is Urllib built in Python 3?

The urllib module in Python 3 allows you access websites via your program. This opens up as many doors for your programs as the internet opens up for you. urllib in Python 3 is slightly different than urllib2 in Python 2, but they are mostly the same.

What is import Urllib parse?

Source code: Lib/urllib/parse.py. This module defines a standard interface to break Uniform Resource Locator (URL) strings up in components (addressing scheme, network location, path etc.), to combine the components back into a URL string, and to convert a “relative URL” to an absolute URL given a “base URL.”


2 Answers

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 
like image 114
Agnaldo Marinho Avatar answered Sep 17 '22 08:09

Agnaldo Marinho


You want urlparse using python2:

from urlparse import urlparse 
like image 33
Padraic Cunningham Avatar answered Sep 17 '22 08:09

Padraic Cunningham