首页 > 解决方案 > echo $PATH 显示一个 Python.Framework 目录。重新启动终端后更改被撤销

问题描述

所以我跑了brew doctor,结果是这样的:

Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:
  /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7-config
  /Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m-config
  /Library/Frameworks/Python.framework/Versions/3.7/bin/python3-config

Warning: Unbrewed header files were found in /usr/local/include.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

然后当我输入export PATH=/usr/bin:/bin:/usr/sbin:/sbin并回显 $PATH 时,它给了我export PATH=/usr/bin:/bin:/usr/sbin:/sbin但是,当我重新启动终端(iTerm2 zsh)时,它又回到/Library/Frameworks/Python.framework/Versions/3.7/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

这个 $PATH 看起来不正确。我对 $PATH 了解不多,但是有没有办法将其修复为应有的状态?我还尝试编辑.bash_profile并放置PATH=/usr/bin:/bin:/usr/sbin:/sbin路径而不是 python 路径-当我回显 $PATH 时仍然没有运气,它仍然是带有 python 的路径。请帮助我,这很令人沮丧。

标签: bashterminalpathzshiterm2

解决方案


您应该放入PATH~/.bashrc不是~/.bash_profile.

因为~/.bash_profile仅当 bash 作为登录 shell 调用时才会生效,这意味着您应该重新登录或使用该--login选项运行 bash。

~/.bashrc,相反,将在启动交互式 shell 时读取并执行。这在您重新启动终端时有效。


编辑:对不起,我发现你的外壳是 zsh。上面的答案是针对 bash 的。

对于 zsh,PATH放入$ZDOTDIR/.zshrc.

然后从 读取命令$ZDOTDIR/.zshenv。如果 shell 是登录 shell,则从 读取命令/etc/zsh/zprofile,然后$ZDOTDIR/.zprofile.

然后,如果 shell 是交互式的,则从 读取命令/etc/zsh/zshrc,然后$ZDOTDIR/.zshrc.

最后,如果shell是一个登录shell,/etc/zsh/zlogin并且$ZDOTDIR/.zlogin被读取。

如果您不设置ZDOTDIR变量,则这些文件位于您的主目录中。


推荐阅读