Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sudo: pip: command not found in CentOS

Tags:

I use CentOS and I installed pip to /usr/local/python-dir/bin/pip. I made a link to /usr/local/bin/pip. Then I executed sudo pip install xxx, it reported an error like this:

sudo: pip: command not found 

I see $PATH is all right:

/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin 

However, I can only execute pip this way:

sudo /usr/local/bin/pip install xxx 

How can I configure PATH or something else? Thanks a lot.

like image 524
zimmer Avatar asked Aug 15 '15 01:08

zimmer


People also ask

Where is pip installed on CentOS?

Python PIP is not available in the official package repository of CentOS 7. But it is available in the EPEL package repository. Before you can install Python PIP on CentOS 7, you must add EPEL repository to your CentOS 7. Press 'y' and then press <Enter> to continue.


2 Answers

For security reasons, sudo does not rely on the $PATH set in your environment. There is a secure_path option in /etc/sudoers that specifies the PATH that sudo will use for locating binaries. For example:

Defaults    secure_path = /sbin:/bin:/usr/sbin:/usr/bin 

Just add /usr/local/bin to this PATH, or get used to typing:

sudo `which pip` install xxx 
like image 59
larsks Avatar answered Oct 01 '22 22:10

larsks


Not ideal but works. You can always unlink it after the install to restore security.

sudo ln -s /usr/local/bin/pip /bin/pip 

Puts pip in the root path bin. You can then run pip as sudo.

like image 32
Paul Kenjora Avatar answered Oct 02 '22 00:10

Paul Kenjora