Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade pip in Amazon Linux

I wanted to deploy my Python app on Amazon Linux AMI 2015.09.1, which has Python2.7 (default) and pip (6.1.1). Then, I upgraded the pip using the command:

sudo pip install -U pip 

However, it seemed broken, and showed the message when I tried to install packages:

pkg_resources.DistributionNotFound: pip==6.1.1 

I found out that pip remove the previous files located in /usr/bin/, and installed the new one in /usr/local/bin. Thus, I tried to specify the location by using the command:

sudo pip install -U --install-option="--prefix='/usr/bin'" pip 

Nevertheless, it still installed the new one in /usr/local/bin. In addition to that, pip could not work well with sudo although it successfully installed. The error message :

sudo: pip2.7: command not found 

Is there a way to properly manage pip?

like image 979
zeck Avatar asked Dec 05 '15 09:12

zeck


People also ask

How can I upgrade my pip version?

Updating Pip b is available.” You can run “pip install --upgrade pip” to install and use the new version of pip. To update pip2 or pip3 using this command, only replace the first pip with the pip version.

How do I install pip on Amazon?

Install pip by using the script provided by the Python Packaging Authority, and then install the EB CLI. Download the installation script from pypa.io . The script downloads and installs the latest version of pip and another required package named setuptools . Run the script with Python.


2 Answers

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.

like image 148
Jihoon Baek Avatar answered Oct 11 '22 14:10

Jihoon Baek


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 sys from pkg_resources import load_entry_point  if __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.

like image 31
Sector95 Avatar answered Oct 11 '22 16:10

Sector95