Fix Pip Error – TypeError: unorderable types: NoneType() < str()

If you haven’t upgraded your pip/pip3 yet, you might be having a difficulty in installing packages or modules for python3+ like below:

Exception:
Traceback (most recent call last):
  File "/usr/lib/python3.4/site-packages/pip/basecommand.py", line 232, in main
    status = self.run(options, args)
  File "/usr/lib/python3.4/site-packages/pip/commands/install.py", line 339, in run
    requirement_set.prepare_files(finder)
  File "/usr/lib/python3.4/site-packages/pip/req/req_set.py", line 229, in prepare_files
    req_to_install.check_if_exists()
  File "/usr/lib/python3.4/site-packages/pip/req/req_install.py", line 931, in check_if_exists
    self.satisfied_by = pkg_resources.get_distribution(self.req)
  File "/usr/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 461, in get_distribution
    dist = get_provider(dist)
  File "/usr/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 341, in get_provider
    return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
  File "/usr/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 870, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 740, in resolve
    env = Environment(self.entries)
  File "/usr/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 927, in __init__
    self.scan(search_path)
  File "/usr/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 957, in scan
    self.add(dist)
  File "/usr/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py", line 977, in add
    dists.sort(key=operator.attrgetter('hashcmp'), reverse=True)
TypeError: unorderable types: NoneType() < str()

To fix this, in my case for python3.4 (Distro: Manjaro), edit __init__.py of pip package:

# edit this file
/usr/lib/python3.4/site-packages/pip/_vendor/pkg_resources/__init__.py
#
# look for lines
_remove_md5_fragment(self.location),
self.py_version,
self.platform,
#
# and change these lines to
_remove_md5_fragment(self.location),
self.py_version or '',
self.platform or '',

You may take a look at this commit: c995677d5321.

The above solution is manual. You may also upgrade pip itself.

sudo pip install --upgrade pip