在Mac OS X 10.8.1上安装lxml时我做错了什么?

Jed*_*sen 8 python macos installation lxml

我正在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
Run Code Online (Sandbox Code Playgroud)

[剪断]

  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
Run Code Online (Sandbox Code Playgroud)

[剪断]

  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
Run Code Online (Sandbox Code Playgroud)

[剪断]

  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
Run Code Online (Sandbox Code Playgroud)

我想在这里弄清楚什么是错的,我在我的深度之外. 任何人都能指出我需要做些什么来解决这个问题吗?

aba*_*ert 17

这是libxml2 2.9中的一个错误.

你得到的错误是在这一行:

once_control = PTHREAD_ONCE_INIT;
Run Code Online (Sandbox Code Playgroud)

这是非法代码,恰好在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}}
Run Code Online (Sandbox Code Playgroud)

看起来这几天前已经报告给了libxml2邮件列表(https://mail.gnome.org/archives/xml/2012-Stembert/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 2.7.8附带的libxml2版本并没有"可怕的过时" - 比他建议使用的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
Run Code Online (Sandbox Code Playgroud)

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

将来,如果您不想处理调试版本,我建议只使用pip安装Python软件包,然后使用Homebrew安装任何缺少的依赖项.您可能无法总是获得最新版本的所有内容的理想版本,但它会更容易,通常也足够好.