Upgrade pip in Amazon Linux Upgrade pip in Amazon Linux python python

Upgrade pip in Amazon Linux


Try:

sudo which pip

This may reveal something like 'no pip in ($PATH)'.

If that is the case, you can then do:

which pip

Which will give you a path like /usr/local/bin/pip.

Copy + paste the path to pip to the sbin folder by running: sudo cp /usr/local/bin/pip /usr/sbin/

This will allow you to run sudo pip without any errors.


Struggled with this for a while. Here's what I've found:

  • ec2_user finds the pip executable, but has a module import error due to other having no read/execute permissions on the pip folders in the /usr/local/lib/python2.7/site-packages folder. This is actually okay, since in most cases, pip installs fail when not run as root anyway.
  • sudo cannot find pip.
  • Entering root with sudo su - allows pip to be run without issue.

The reason sudo pip stops working after the upgrade, is because the executable (or symbolic link) is removed from /usr/bin. However, what remains is a file called pip-27, which contains the following:

#!/usr/bin/python2.7# EASY-INSTALL-ENTRY-SCRIPT: 'pip==6.1.1','console_scripts','pip2.7'__requires__ = 'pip==6.1.1'import sysfrom pkg_resources import load_entry_pointif __name__ == '__main__':    sys.exit(        load_entry_point('pip==6.1.1', 'console_scripts', 'pip2.7')()    )

So, that's where our error comes from, as the upgrade clearly doesn't clean this file up. Not entirely clear on where the name translation from pip to pip-2.7 occurs.

As mentioned in another answer, pip now exists in /usr/local/bin after the upgrade, which is no longer in the sudo secure path. You can add this path to the secure_path variable by running sudo visudo. Another alternative, if you'd prefer to not add that path to your secure_path is to make a symbolic link to the new pip executable in /usr/bin.


The problem is partly answered by your question. The Amazon AMI doesn't consider /usr/local/bin to be part of the root account's PATH. You can fix this by updating the root account's ~/.bashrc to include it.

Something like this...

export PATH=$PATH:/usr/local/bin