【问题标题】:Error when installing lxml on MacOSX 10.7.5:在 MacOSX 10.7.5 上安装 lxml 时出错:
【发布时间】:2013-06-28 22:33:14
【问题描述】:

我在尝试使用 Homebrew 和 pip 在 MacOSX 10.7.5 上安装 lxml 时遇到了很多问题。我有安装了命令行工具的 Xcode 4.6.3。以下是我的具体步骤:

$ export CC=llvm-gcc-4.2
$ export CXX=llvm-g++-4.2
$ brew install --use--llvm libxml2
$ brew install --use-llvm libxslt
$ sudo pip install lxml

brew 安装成功完成,但 pip install 给我以下错误:

error: command 'cc' failed with exit status 1

完整日志在这里:https://gist.github.com/sloria/5902993

当我尝试使用 easy_install 时:

$ sudo easy_install lxml

我得到一个不同的错误:

error: Setup script exited with error: command 'cc' failed with exit status 1

完整日志在这里:https://gist.github.com/sloria/5903014

这是怎么回事?

【问题讨论】:

  • 错误一目了然:'libxml/xmlversion.h' file not found

标签: python macos lxml pip homebrew


【解决方案1】:

尝试使用系统 clang 编译器(无 --use-llvm 标志)并执行 brew doctor,因为您不需要将 sudo 与 pip 一起使用。访问权限可能存在问题,因此可能无法读取 libxml/xmlversion.h。 您是否使用 brew 安装了 python/pip?混合 brew 和非 brew 安装的应用程序有时是个问题。

我在我的系统(Mac OSX 10.8.4 和 Xcode 4.6.3)上尝试过:

brew install libxml2
brew install libxslt
pip install lxml

一切都很好。

【讨论】:

  • 我试过了,但我得到了和上面一样的错误(第一个)。
  • brew医生说一切正常?
  • 啊,是的,我从 brew doctor 的处方中找到了答案。见我上面的回答。感谢您的帮助。
【解决方案2】:

找到我的解决方案:Postgres.app 的配置脚本让 Homebrew 感到困惑。

这只是从我的路径中删除Applications/Postgres.app/Contents/MacOS/bin/ 的问题。

然后我为psql 脚本添加了一个别名:alias psql="Applications/Postgres.app/Contents/MacOS/bin/psql"

更多信息来自brew doctor

"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:

【讨论】: