【问题标题】:What am I doing wrong when installing lxml on Mac OS X 10.8.1?在 Mac OS X 10.8.1 上安装 lxml 时我做错了什么?
【发布时间】:2012-09-11 04:03:14
【问题描述】:

我正在 Mac OS X 10.8.1 和 Python 2.7.2 上构建 lxml 并遇到问题。 (我已经克隆了 Github 存储库,并在此处按照 Mac OS X 的说明进行操作:http://lxml.de/build.html

在构建 libxml2 时出现了一些问题;以下是终端输出的尾端:

configure: creating ./config.status
config.status: creating libxml2.spec
config.status: creating Makefile
config.status: creating include/Makefile
config.status: creating include/libxml/Makefile
config.status: creating doc/Makefile
config.status: creating doc/examples/Makefile
config.status: creating doc/devhelp/Makefile
config.status: creating example/Makefile
config.status: creating python/Makefile
config.status: creating python/tests/Makefile
config.status: creating xstc/Makefile
config.status: creating include/libxml/xmlversion.h
config.status: creating xml2-config
config.status: creating libxml-2.0.pc
config.status: creating libxml-2.0-uninstalled.pc
config.status: creating python/setup.py
config.status: creating config.h
config.status: executing depfiles commands
config.status: executing libtool commands
rm: libtoolT: No such file or directory
Done configuring
make  all-recursive
Making all in include
Making all in libxml
make[3]: Nothing to be done for `all'.
make[3]: Nothing to be done for `all-am'.
Making all in .
  CC     error.lo

[截图]

  CC     hash.lo
parser.c: In function 'xmlParseInNodeContext':
parser.c:13492: warning: pointer targets in passing argument 1 of 'xmlFindCharEncodingHandler' differ in signedness
  CC     list.lo

[截图]

  CC     xpointer.lo
xpath.c: In function 'xmlXPathRegisterFuncNS':
xpath.c:4870: warning: ISO C forbids passing argument 4 of 'xmlHashAddEntry2' between function pointer and 'void *'
xpath.c: In function 'xmlXPathFunctionLookupNS':
xpath.c:4951: warning: ISO C forbids assignment between function pointer and 'void *'
xpath.c: In function 'xmlXPathCompOpEval':
xpath.c:13535: warning: ISO C forbids assignment between function pointer and 'void *'
xpath.c:13562: warning: ISO C forbids assignment between function pointer and 'void *'
xpath.c: At top level:
trionan.c:221: warning: 'trio_is_negative' defined but not used
  CC     xinclude.lo

[截图]

  CC     xmlstring.lo
threads.c: In function 'xmlCleanupThreads':
threads.c:918: error: expected expression before '{' token
make[2]: *** [threads.lo] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
Traceback (most recent call last):
  File "setup.py", line 225, in <module>
    **setup_extra_options()
  File "setup.py", line 139, in setup_extra_options
    STATIC_CFLAGS, STATIC_BINARIES)
  File "/Users/jedc/Downloads/lxml/setupinfo.py", line 57, in ext_modules
    multicore=OPTION_MULTICORE)
  File "/Users/jedc/Downloads/lxml/buildlibxml.py", line 338, in build_libxml2xslt
    cmmi(libxml2_configure_cmd, libxml2_dir, multicore, **call_setup)
  File "/Users/jedc/Downloads/lxml/buildlibxml.py", line 266, in cmmi
    cwd=build_dir, **call_setup)
  File "/Users/jedc/Downloads/lxml/buildlibxml.py", line 249, in call_subprocess
    raise Exception('Command "%s" returned code %s' % (cmd_desc, returncode))
Exception: Command "make -j5" returned code 512

我在试图找出这里出了什么问题时已经超出了我的深度。 谁能指出我需要做些什么来解决这个问题?

【问题讨论】:

    标签: python macos installation lxml


    【解决方案1】:

    这是 libxml2 2.9 中的一个错误。

    你得到的错误在这一行:

    once_control = PTHREAD_ONCE_INIT;
    

    这是非法代码,恰好可以在 linux 上运行。 PTHREAD_ONCE_INIT 只能用于初始化,不能用于赋值,这是有特定原因的:因此平台可以将 PTHREAD_ONCE_INIT 定义为聚合初始化器。 OS X 可以。来自 10.8.1 的/usr/include/pthread.h

    #define PTHREAD_ONCE_INIT {_PTHREAD_ONCE_SIG_init, {0}}
    

    看起来这已经在几天前被报告到 libxml2 邮件列表(https://mail.gnome.org/archives/xml/2012-September/msg00036.html),两天后在 bugzilla 中提交( https://bugzilla.gnome.org/show_bug.cgi?id=684024),并在第二天修复(http://git.gnome.org/browse/libxml2/commit/?id=3f6cfbd1d38d0634a2ddcb9a0a13e1b5a2195a5e),所以大概是2.9 .1不会有这个问题。

    所以,这里是你的选择:

    当然你可以等 2.9.1 出来。

    替代方案,尽管构建页面上说了什么,Mountain Lion 附带的 libxml2 版本 2.7.8 并没有“严重过时”——它比他建议使用的 2.7.3 版本更新。因此,您可以跳过--static-deps 并使用内置的 2.7.8。

    如果您确实想要比 2.7.8 更新的东西,但不像(非工作)2.9.0 那样新,构建页面会显示如何明确指定它,http://www.xmlsoft.org 应该有版本历史记录所以你可以选择你想要的版本。例如:

    python setup.py build --static-deps \
       --libxml2-version=2.8.0
    

    或者您可以手动应用来自 http://git.gnome.org/browse/libxml2/commit/?id=3f6cfbd1d38d0634a2ddcb9a0a13e1b5a2195a5e 的补丁并手动构建它,或者拉动树的顶部而不是版本 2.9.0,构建它,然后告诉 lxml 使用该构建。

    将来,如果您不想处理调试构建,我建议您只使用 pip 安装 Python 包,并使用 Homebrew 安装任何缺少的依赖项。您可能并不总是获得所有最新版本的理想构建,但它会容易得多,而且通常足够好。

    【讨论】:

    • 哇,非常感谢您提供的令人难以置信的全面答案!我知道我一开始尝试使用 pip 但它没有用;我现在刚刚试了一下,它成功完成了。 (最后的终端输出=“成功安装lxml”)但是当我进入python并输入“import lxml”时,我得到“ImportError:没有名为lxml的模块”。关于我做错了什么有什么想法吗?
    • 您有任何非 Apple Python 安装吗?您可能正在运行不匹配的 pip 和 python 版本。一个很常见的事情是,您最终将 /usr/local/bin/pip(或 /opt/local/bin/pip 等)作为路径上的第一个 pip,它会为 /usr/local/ 安装模块bin/python,然后 /usr/bin/python 作为第一个 python。
    • 我很可能在某个时候把它搞砸了。我该如何诊断? (我是 UNIX 命令/路径/协议的真正新手!)
    • 当我运行“which python”时,我得到:/Library/Frameworks/Python.framework/Versions/2.7/bin/python,当我运行“which pip”时,我得到:/usr/local/ bin/pip 这有帮助吗?
    • 好的,听起来你有 两个 非 Apple pythons。 /Library/... 中的那个可能来自 python.org 或“包含更多电池”的发行版之一(可能是科学发行版或 ActiveState 之一); /usr/local/Cellar/python 中的那个绝对是 Homebrew 的。路径中的第一个 python 是第一个,但路径中的第一个 pip 是 Homebrew 的。因此,您正在将包安装到一个 Python,然后运行另一个。
    猜你喜欢
    • 1970-01-01
    • 2013-11-02
    • 2015-01-20
    • 2013-04-10
    • 2015-08-05
    • 2015-12-10
    • 2011-05-16
    • 2015-12-06
    相关资源
    最近更新 更多