【问题标题】:How do I install lxml on Mac OS X 10.7.4? I have exhausted all options如何在 Mac OS X 10.7.4 上安装 lxml?我已经用尽了所有选项
【发布时间】:2012-05-26 20:25:56
【问题描述】:

尝试了各种途径,但没有运气。我正在使用 10.7.4 的 MBP。我不记得上次在我的 Mac 上使用 Python 安装任何东西时遇到这么多问题是什么时候了。请帮助我在本地机器上使用 lxml,而不是依赖 SVN 提交、更新以在 Linux 机器上远程运行。

$ sudo STATIC_DEPS=true /usr/bin/easy_install-2.7 lxml
Password:
Searching for lxml
Reading http://pypi.python.org/simple/lxml/
Reading http://codespeak.net/lxml
Best match: lxml 2.3.4
Downloading http://lxml.de/files/lxml-2.3.4.tgz
Processing lxml-2.3.4.tgz
Running lxml-2.3.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-mbyEtk/lxml-2.3.4/egg-dist-tmp-O_t_3P
Building lxml version 2.3.4.
Latest version of libiconv is 1.14
Downloading libiconv into libs/libiconv-1.14.tar.gz
error: [Errno 60] Operation timed out

尝试了以下没有运气

$ python setup.py build

$ STATIC_DEPS=true sudo easy_install --allow-hosts=lxml.de,*.python.org lxml
$ sudo pip install lxml

llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -I/usr/include/libxml2 -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.macosx-10.7-intel-2.7/src/lxml/lxml.etree.o -w -flat_namespace

unable to execute llvm-gcc-4.2: No such file or directory

error: command 'llvm-gcc-4.2' failed with exit status 1

【问题讨论】:

  • 你的~/.pip/pip.log 说什么?
  • @mata : -bash: /Users/ThinkCode/.pip/pip.log: 没有这样的文件或目录
  • @ThinkCode - 如果您以 root 身份运行 pip,那么日志应该在 /root/.pip/pip.log 中。但正如@larsks 指出的那样,您需要确保在您的$PATH 中安装了gcc。

标签: python macos osx-lion installation lxml


【解决方案1】:

对于正在浏览此页面的未来用户,这里是在 Mac OSX 上安装 lxml 的分步指南。

  1. 转到 Xcode,转到首选项,然后转到下载选项卡,然后选择“命令行工具”。下载命令行工具

  2. 依次转到应用程序、实用程序和终端,然后打开终端。在终端中,输入“easy_install pip”。注意:如果显示“错误:/usr/local/bin/pip: Permission denied”,则输入“chmod 777 /usr/local/bin/”。现在再次尝试第 2 步。

  3. 类型:pip install "Cython>=0.18"

  4. 完成后,输入:pip install lxml

  5. 打开python IDLE,测试能不能导入lxml,玩得开心!

【讨论】:

  • 这还不够;尝试输出:/lxml/src/lxml/includes/etree_defs.h:9:10: 致命错误:找不到“libxml/xmlversion.h”文件
  • 就我而言,我之所以能够使用pip install lxml,部分原因是我已经安装了 Xcode 和相当新的 Cython 版本。
【解决方案2】:

我必须这样做: “sudo port uninstall py-lxml”、“sudo port uninstall py24-lxml”和“sudo port install py27-lxml”,然后我用 pip 卸载了 lxml,然后用 pip 重新安装,它工作了!

【讨论】:

【解决方案3】:

我先安装了MacPorts,然后:

$ sudo port install python27 py27-lxml

这给了我一个正常运行的 lxml 安装。

关于您的错误消息,您似乎缺少pip 用于构建lxml (llvm-gcc-4.2) 的编译器命令。您是否安装了 OS X 开发工具?您应该在/usr/bin/llvm-gcc-4.2 中找到该文件;如果不存在,您可能需要下载并安装开发包。

您可以通过 App Store 安装 XCode 开发者工具。如果您阅读应用商店中的 cmets,您会注意到为了使命令行工具可用,您需要单独安装它们。在 XCode 中,转到 Preferences->Downloads 并下载“命令行工具”包。

【讨论】:

  • 我可以在没有 MacPorts 的情况下安装它吗?
  • 当然,有可能。但总的来说,我宁愿花时间使用该软件,所以我很乐意利用那些使安装软件变得更容易的东西。
  • 我会等待任何其他答案,如果我无法安装 lxml,我最终会求助于 MacPorts。非常感谢。赞成。
  • 是的,您缺少命令行工具。看我的更新。这显然是最近的变化——旧版本的 XCode Just Worked。
  • 'sudo pip install lxml' 在我安装了“命令行工具”之后成功了。 'sudo port install python27 py27-lxml' 给出了一个错误(错误:处理端口 python27 失败)。我仍然选择这个答案。感谢“命令行工具”的建议。感谢 Apple 没有默认安装它们 ;)
猜你喜欢
  • 1970-01-01
  • 2012-09-11
  • 2013-11-02
  • 2013-04-10
  • 2012-07-16
  • 1970-01-01
  • 2012-05-20
  • 1970-01-01
相关资源
最近更新 更多