简体   繁体   English

sudo -H pip install 和 pip --user install 的区别

[英]Difference between sudo -H pip install and pip --user install

I am wondering what is the difference between these two commands (I have the feeling that they are identical):我想知道这两个命令之间有什么区别(我觉得它们是相同的):

  • sudo -H pip install <package>
  • pip --user install <package>

More informations:更多信息:
From the sudo manpage:从 sudo 联机帮助页:

-H, --set-home
    Request that the security policy set the HOME environment
    variable to the home directory specified by the target user's
    password database entry. Depending on the policy, this may be
    the default behavior.

And the pip user guide: https://pip.pypa.io/en/stable/user_guide/和 pip 用户指南: https://pip.pypa.io/en/stable/user_guide/


Related questions:相关问题:
What is the difference between pip install and sudo pip install? pip 安装和 sudo pip 安装有什么区别?
What is the purpose of "pip install --user..."? “pip install --user ...”的目的是什么? and
sudo pip install VS pip install --user sudo pip 安装 VS pip 安装 --user
But none of them talk about the sudo -H option or the precise difference between the two.但是他们都没有谈论sudo -H选项或两者之间的确切区别。

sudo is short for 'superuser do'. sudo 是“超级用户做”的缩写。 It simply runs the command with root privileges, which may be useful if you are installing to a directory you normally wouldn't have access to.它只是以 root 权限运行命令,如果您要安装到通常无法访问的目录,这可能很有用。

However, in the examples you have given the two commands would function identically, as you don't need root privileges to pip install --user但是,在您给出的示例中,这两个命令的功能相同,因为您不需要 root 权限来pip install --user

The difference comes down to the permissions that are given to the package, and the location where the package is installed.区别归结为授予 package 的权限,以及 package 的安装位置。 When you run a command as root, the package will be installed with root permissions.当您以 root 身份运行命令时,package 将以 root 权限安装。

Here's an example:这是一个例子:

Running sudo -H pip3 install coloredlogs results in the following:运行sudo -H pip3 install coloredlogs结果如下:

$ sudo pip3 show coloredlogs | grep Location
Location: /usr/local/lib/python3.8/dist-packages

$ ls -l /usr/local/lib/python3.8/dist-packages
drwxr-sr-x 4 root staff 4096 Feb 25 01:14 coloredlogs

$ which coloredlogs
/usr/local/bin/coloredlogs

Running pip3 install --user <package> results in the following:运行pip3 install --user <package>结果如下:

$ pip3 show coloredlogs | grep Location
Location: /home/josh/.local/lib/python3.8/site-packages

$ ls -l /home/josh/.local/lib/python3.8/site-packages
drwxrwxr-x 4 josh josh 4096 Feb 25 01:14 coloredlogs

$ which coloredlogs
coloredlogs not found

Notice the location differences between the two, and also notice that the package isn't installed on PATH when installed using the --user flag.请注意两者之间的位置差异,并注意使用--user标志安装时 package 未安装在 PATH 上。 If for some reason I wanted to directly call the package, I would need to add /home/josh/.local/bin to my PATH.如果出于某种原因我想直接调用 package,我需要将/home/josh/.local/bin添加到我的路径中。

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

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