zimmer zimmer - 2 months ago 41
Python Question

sudo: pip: command not found in CentOS

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.

Answer

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