Homebrew:在安装 Formulas 之前修改了 PATH env var(mercurial 将使用系统 python 而不是 homebrew python)

Homebrew: PATH env var is modified before installation of Formulae (mercurial will use system python instead of homebrew python)

尝试在 Mac OS X 10.9 上使用 Homebrew 来安装 mercurial 并确保它使用的是 homebrew python 版本。

我已将 /etc/paths 更新为在 /usr/bin 之前列出 /usr/local/bin

使用 brew install python 安装 python 2.7.9,python 可执行文件位于 /usr/local/bin/python,它是 /usr/local/Cellar/python/2.7.9/bin/python.[=41 的符号链接=] 当我输入 which pythonpython -V 时,我得到的是自制软件 python 版本。

后来,当我运行brew install mercurial安装的文件/usr/local/bin/hgshebang(#!)指向系统python/usr/bin/python
发生这种情况是因为 mercurial python 软件包安装程序 (distutils) 正在使用 PATH 变量将路径硬编码到 shebang 中的 python 而不是 #!/usr/bin/env python.

当我检查我的 PATH 环境变量时,我在 /usr/bin 之前看到 /usr/local/bin,但是如果我尝试以交互方式安装 brew 包:brew install -i mercurial 我得到一个 shell使用完全没有 /usr/local/bin 的不同 PATH 变量。

如何安装 mercurial 以确保它将使用 python 的自制版本? 我更喜欢一种也能在 mercurial 包升级中幸存下来的方法。

默认情况下,公式仅使用系统 Python。您可以绕过 Superenv(清理 PATH),它应该在从源代码构建时获取 PATH 中的任何内容:

$ brew reinstall mercurial --build-from-source --env=std
$ head -n 1 /usr/local/bin/hg  
#!/usr/local/opt/python/bin/python2.7