【问题标题】:Can't set Homebrew python to bet the default python?无法设置 Homebrew python 来赌默认 python?
【发布时间】:2017-09-10 12:35:51
【问题描述】:

我刚刚擦除了我的 Mac 并重新安装了 macOS。

我安装了 Homebrew,然后使用 brew install python 安装了 Python。但现在如果我使用which python,我会得到/usr/bin/python。当输入echo $PATH 时,它会返回usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin。

我的 .bash_profile 文件:

# Load the shell dotfiles, and then some:
# * ~/.path can be used to extend `$PATH`.
# * ~/.extra can be used for other settings you don’t want to commit.
for file in ~/.{path,bash_prompt,exports,aliases,functions,extra}; do
  [ -r "$file" ] && source "$file"
done
unset file

# Brew Cask install location
export HOMEBREW_CASK_OPTS="appdir=~/Applications"

我的 .path 文件:

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

我需要做什么才能将 Homebrew Python 设置为默认值?

//编辑 我刚刚用 Homebrew 安装了 ruby​​,它可以工作,但 Python 不能...

//edit2some adjustments

【问题讨论】:

  • 某处有错别字:您声称的输出中的usr/local/bin 与/usr/local/bin 不同。
  • 它可能在哪个文件中?我在 .bash_profile 和 .path 中找不到...
  • 路径似乎不太匹配,如果您刚刚开始使用自制软件,那么可以让您的生活更简单的一件事是使用本地的非特权前缀。
  • @VenatorScientiae 这可能只是你的问题;也许echo $PATH 确实返回/usr/local/bin/... 而不是usr/local/bin:...。但是,我们无法确定是哪种情况。
  • which -a python 的输出是什么?

标签: python macos terminal homebrew


【解决方案1】:

你需要修改你的$PATH,安装Python时检查homebrew的输出brew install python:

==> Caveats
This formula installs a python2 executable to /usr/local/bin.
If you wish to have this formula's python executable in your PATH then add
the following to ~/.zshrc:
  export PATH="/usr/local/opt/python/libexec/bin:$PATH"

Pip and setuptools have been installed. To update them
  pip2 install --upgrade pip setuptools

You can install Python packages with
  pip2 install <package>

They will install into the site-package directory
  /usr/local/lib/python2.7/site-packages

See: http://docs.brew.sh/Homebrew-and-Python.html

这样的事情应该可以工作:

export PATH="/usr/local/opt/python/libexec/bin:$HOME/Library/Python/2.7/bin:$HOME/Library/Python/3.6/bin:..."

【讨论】:

    猜你喜欢
    • 2022-11-25
    • 2014-06-19
    • 1970-01-01
    • 2014-08-29
    • 1970-01-01
    • 1970-01-01
    • 2017-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多