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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32020594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:53:18  来源:igfitidea点击:

sudo: pip: command not found in CentOS

pythoncentospip

提问by zimmer

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:

我使用 CentOS 并将 pip 安装到/usr/local/python-dir/bin/pip. 我做了一个链接到/usr/local/bin/pip. 然后我执行了sudo pip install xxx,它报了这样的错误:

sudo: pip: command not found

I see $PATHis 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? Thanks a lot.

如何配置 PATH 或其他东西?非常感谢。

采纳答案by larsks

For security reasons, sudodoes not rely on the $PATHset in your environment. There is a secure_pathoption in /etc/sudoersthat specifies the PATHthat sudowill use for locating binaries. For example:

出于安全原因,sudo不依赖$PATH于您的环境中的设置。有一个secure_path在选项/etc/sudoers指定PATHsudo将用于定位二进制文件。例如:

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

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

只需添加/usr/local/bin到此 PATH,或者习惯键入:

sudo `which pip` install xxx

回答by crowdedComputeeer

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

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

$ sudo -E pip install xyz

$ sudo -E pip install xyz

回答by Mark Reed

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

尝试sudo bash -c 'echo $PATH'查看在哪里sudo寻找命令;然后,您可以符号链接pip到这些目录之一。

回答by Paul Kenjora

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.

将 pip 放在根路径 bin 中。然后,您可以以 sudo 身份运行 pip。

回答by Madhu M B

pip can be installed with below command :

pip 可以使用以下命令安装:

yum -y install python-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