python3
supports urllib.parse
and python2
supports urlparse
If you want both compatible then the following code can help.
import sys
if ((3, 0) <= sys.version_info <= (3, 9)):
from urllib.parse import urlparse
elif ((2, 0) <= sys.version_info <= (2, 9)):
from urlparse import urlparse
Update: Change if condition to support higher versions if (3, 0) <= sys.version_info:
.