zimmer
zimmer

Reputation: 1197

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.

Upvotes: 24

Views: 52804

Answers (6)

Micheal Bee
Micheal Bee

Reputation: 628

On my system, I have miniconda installed; so any terminal I open is initially in the base environment. To install pip packages globally, I need to "conda deactivate" first, out of the base environment. Then when I "pip install" a package, it can be seen by the system globally.

Upvotes: 0

crowdedComputeeer
crowdedComputeeer

Reputation: 469

You can add the -E option to sudo to use the environmental variables of your user account

$ sudo -E pip install xyz

Upvotes: 0

Paul Kenjora
Paul Kenjora

Reputation: 2004

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.

Upvotes: 11

Madhu M B
Madhu M B

Reputation: 31

pip can be installed with below command :

yum -y install python-pip

If your facing any problem with GPG key (no such file or directory), then trigger below command:

rpm --import http://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-6

then try install pip

Upvotes: 3

Mark Reed
Mark Reed

Reputation: 95242

Try sudo bash -c 'echo $PATH' to see where sudo is looking for commands; you can then symlink pip into one of those directories.

Upvotes: 4

larsks
larsks

Reputation: 311288

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

Upvotes: 57

Related Questions