Problems with Pip

Broken pip (Ubuntu 16.04 & 18.04)

Ubuntu has packages for pip (python-pip and python3-pip), but they are an older version (e.g. pip 8.1.1 on Ubuntu 16.04 and pip 9.0.1 on Ubuntu 18.04). While the Freedom Agent is compatible with the older versions of pip, upgrading to the latest version of pip is recommended to allow faster installations.

We recommend installing latest pip in a local user space:

pip install --user -U pip

If you try to update pip by running a command like pip install -U pip (while not having a python virtual environment activated), the new version of pip will be installed globally, but the pip executable (/usr/bin/pip) provided by the OS will break. You may see an error like this:

/usr/bin/pip -V
Traceback (most recent call last):
  File "/usr/bin/pip", line 9, in <module>
    from pip import main
ImportError: cannot import name main

/usr/local/bin/pip -V
pip 19.2.3 from /usr/local/lib/python2.7/dist-packages/pip (python 2.7)

While the Freedom Agent can complete the installation because it does not call the pip executable directly (or from that path), this is an issue that can be solved.

Here are two ways to fix this issue:

Keep just the newest pip version

apt-get purge python-pip

Notes:

  • Start a new terminal to test that pip is working correctly.

Keep just the OS pip package

python -m pip uninstall pip
apt-get install python-pip --reinstall

Notes:

  • When uninstalling the new pip python module, it will also remove the pip executables from /usr/bin (including pip3 if present). This is why we have to reinstall the OS package.
  • On Ubuntu 18.04, if the pip3 executable was removed from /usr/bin, you will have to also reinstall python3-pip.
apt-get install python3-pip --reinstall
  • On Ubuntu 16.04, if the pip3 executable was removed from /usr/bin, you will have to also reinstall python.