Homebrew取代Python3,如何逆转?

Homebrew取代Python3,如何逆转?

当尝试在 Linux 机器上安装 AWS SAM CLI 时,我必须安装 Homebrew/Linuxbrew。 AWS 软件包依赖于 python 3,我已经将其安装在我的系统上。在自制程序安装日志的中间,我看到了这一点:

==> Pouring python-3.7.4.x86_64_linux.bottle.tar.gz
==> /home/linuxbrew/.linuxbrew/Cellar/python/3.7.4/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/home/linuxbrew/.linuxbrew/Cellar/python/3.7.4
==> /home/linuxbrew/.linuxbrew/Cellar/python/3.7.4/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/home/linuxbrew/.linuxbrew/Cellar/python/3.7.4
==> /home/linuxbrew/.linuxbrew/Cellar/python/3.7.4/bin/python3 -s setup.py --no-user-cfg install --force --verbose --install-scripts=/home/linuxbrew/.linuxbrew/Cellar/python/3.7.4
==> Caveats
Python has been installed as
  /home/linuxbrew/.linuxbrew/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /home/linuxbrew/.linuxbrew/opt/python/libexec/bin

接下来:

$ which python3
/home/linuxbrew/.linuxbrew/bin/python3

这确实不是请放心,因为它之前没有警告过,让我别无选择,而且我比自制软件更信任我的发行版。

我的第一个想法是删除包:

$ brew uninstall python3
Error: Refusing to uninstall /home/linuxbrew/.linuxbrew/Cellar/python/3.7.4
because it is required by aws-sam-cli, which is currently installed.
You can override this and force removal with:
  brew uninstall --ignore-dependencies python3

这意味着我不能简单地删除它

现在,安装依赖项是可以忍受的,但如果它替换我的系统本机包,那么我的问题是:

有没有办法告诉 homebrew不是将来搞乱我的系统,并找回我的本机 python 吗?

答案1

Linuxbrew 将根据需要安装为您安装的软件包提供依赖项的软件包。有时,这些依赖项(或者就此而言,您安装的软件包brew)将提供与系统上已存在的软件相同的服务或工具。 Linuxbrew 不会代替已通过其他方式安装在系统上的软件,因为它安装的软件安装在完全独立的位置(根据设计)。

要确保 提供的命令brew不优先于以其他方式安装的命令,请确保各种 Linuxbrewbin目录位于您的 中的最后$PATH,或者至少bin保存系统上“本机”命令的目录。

我相信 Linuxbrew 将以下内容添加到用户的~/.bash_profile(或要求用户添加它,我不记得了):

eval $(/home/linuxbrew/.linuxbrew/bin/brew shellenv)

(或类似的东西)。

这会导致命令

export PATH="/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin:$PATH"

执行,这会将 Linuxbrew 路径添加到正面你的$PATH

您可以brew shellenv在终端中运行该命令并将其输出复制到您的~/.bash_profile文件中(应该有许多export语句),完全替换那里相应的调用,并且改变命令export PATH进入

export PATH="$PATH:/home/linuxbrew/.linuxbrew/bin:/home/linuxbrew/.linuxbrew/sbin"

这可确保默认(非 Linuxbrew)中的命令$PATH优先于brew命令。我不能说这是否会破坏任何brew依赖 Linuxbrew 版本命令的软件包。

相关内容