PATH
出于安全原因,Sudo与您当前的用户使用的不是同一用户。其中/etc/sudoers
有一个选项secure_path
,用于指定使用sudo运行命令时使用的路径。我的看起来像这样:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
从sudo联机帮助页:
secure_path Path used for every command run from sudo. If you don't trust the people running sudo to have a sane PATH environment
variable you may want to use this. Another use is if you want to have the “root path” be separate from the “user path”.
Users in the group specified by the exempt_group option are not affected by secure_path. This option is not set by
default.
该pip3
命令可能不在sudoers
文件定义的路径中。您可以将路径添加到secure_path
或提供完整的pip3
命令路径,如下所示:
sudo /path/to/pip3 install django