警告:pip3.8脚本安装在'/usr/local/bin'中,该路径未包含在PATH中。

29

当我运行 pip3.8 时,在我的终端中出现以下警告

WARNING: The script pip3.8 is installed in '/usr/local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-21.1.1 setuptools-56.0.0
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv

如何在CentOS 7上解决此问题?


类似的问题可以在Server Fault论坛上找到:https://serverfault.com/questions/102932/adding-a-directory-to-path-in-centos - Matt Seymour
安装后,注销或重新启动系统对我有效。 - Muhammad Shahzad
3个回答

50

这个问题已经在serverfaults论坛上得到了解答:这里是一个问题的链接

你需要将以下内容添加到你的~/.bash_profile~/.bashrc文件中。

 export PATH="/usr/local/bin:$PATH"

接下来您需要进行性能剖析,可以通过运行以下命令之一来完成:

source ~/.bash_profile

或者通过关闭终端并打开一个新的会话来实现。您应该继续检查您的PATH以确保它包含路径。

echo $PATH

2
bin后面缺少冒号吗? - NorwegianClassic
很好地发现了@NorwegianClassic。 - Matt Seymour

18
其他答案是可行的,但我在AWS Ubuntu 20.04的新安装中发现了一种更符合惯用法的方法。那个路径语句已经存在,但在.profile文件中。您需要退出并重新登录。引入环境变量不起作用。原因:在.profile文件中,代码:
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi

当您登录时,将执行并自动将.local/bin添加到您的路径中。

如果您通过sudo apt install python3-pip安装pip3,则该目录刚刚被创建,并且您尚未注销-因此还没有执行该路径语句。

在执行sudo apt install后,您也可以执行.profile。


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接