简体   繁体   English

sudo: pip: 在 CentOS 中找不到命令

[英]sudo: pip: command not found in CentOS

I use CentOS and I installed pip to /usr/local/python-dir/bin/pip .我使用 CentOS 并将 pip 安装到/usr/local/python-dir/bin/pip I made a link to /usr/local/bin/pip .我做了一个指向/usr/local/bin/pip Then I executed sudo pip install xxx , it reported an error like this:然后我执行sudo pip install xxx ,它报了这样的错误:

sudo: pip: command not found

I see $PATH is all right:我看到$PATH

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

However, I can only execute pip this way:但是,我只能以这种方式执行 pip:

sudo /usr/local/bin/pip install xxx

How can I configure PATH or something else?如何配置 PATH 或其他东西? Thanks a lot.非常感谢。

For security reasons, sudo does not rely on the $PATH set in your environment.出于安全原因, sudo不依赖于您环境中设置的$PATH There is a secure_path option in /etc/sudoers that specifies the PATH that sudo will use for locating binaries. /etc/sudoers中有一个secure_path选项,用于指定sudo用于定位二进制文​​件的PATH For example:例如:

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

Just add /usr/local/bin to this PATH, or get used to typing:只需将/usr/local/bin添加到此 PATH 中,或者习惯键入:

sudo `which pip` install xxx

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.将 pip 放在根路径 bin 中。 You can then run pip as sudo.然后,您可以以 sudo 身份运行 pip。

Try sudo bash -c 'echo $PATH' to see where sudo is looking for commands;尝试sudo bash -c 'echo $PATH'以查看sudo在哪里寻找命令; you can then symlink pip into one of those directories.然后,您可以将pip符号链接到这些目录之一。

pip can be installed with below command : pip 可以使用以下命令安装:

yum -y install python-pip

If your facing any problem with GPG key (no such file or directory), then trigger below command:如果您遇到 GPG 密钥(没有此类文件或目录)的任何问题,请触发以下命令:

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

then try install pip然后尝试安装pip

您可以将-E选项添加到sudo以使用您的用户帐户的环境变量

$ sudo -E pip install xyz

On my system, I have miniconda installed;在我的系统上,我安装了 miniconda; 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.要全局安装 pip 包,我需要首先在基本环境之外“conda 停用”。 Then when I "pip install" a package, it can be seen by the system globally.然后当我“pip install”一个包时,它可以被系统全局看到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM