2012-09-18 97 views
8

我在Mac OS X 10.8.1和Python 2.7.2上構建lxml並遇到問題。 (我已經克隆了Github存儲庫,並按照Mac OS X的說明進行操作:http://lxml.de/build.html在Mac OS X 10.8.1上安裝lxml時,我做錯了什麼?

看起來有些東西在構建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 

I」在我的深度之外,我試圖弄清楚這裏有什麼問題。 任何人都可以指出我需要做什麼來解決這個問題嗎?

回答

17

這是libxml2 2.9中的一個bug。

你得到的錯誤是在這條線:

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出來。儘管構建頁面說了什麼,但2.7.8版本的Mountain Lion提供的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 

或者你也可以手動從http://git.gnome.org/browse/libxml2/commit/?id=3f6cfbd1d38d0634a2ddcb9a0a13e1b5a2195a5e應用補丁和手動構建,或拉樹,而不是2.9.0版本的頂部,構建,然後告訴LXML使用該版本。在未來,如果你不想處理調試構建,我建議只使用pip來安裝Python包,而Homebrew則會安裝任何缺失的依賴項。你可能不會總是得到的一切的最新版本的理想身材,但是這將是一個容易得多,而且通常不夠好。

+0

哇,感謝這麼多令人難以置信的全面的回答!我知道我一開始嘗試使用pip,但它不起作用;我現在只是試了一下,併成功完成。 (末端子輸出=「成功安裝LXML」)但是,當我進入Python和類型「進口LXML」我得到的「導入錯誤:沒有模塊名爲LXML」。關於我在做什麼的任何想法都是錯誤的? –

+1

你有沒有非蘋果Python安裝?您可能正在運行不匹配的pip和python版本。一個很常見的事是,你最終的/ usr/local/bin目錄/ PIP(或/選擇/ local/bin目錄/ PIP等),您的路徑上的第一個點子,並將其安裝模塊的/ usr /本地/ bin/python,但是接下來是/ usr/bin/python作爲第一個python。 – abarnert

+0

這很可能是我設法螺絲,最多在某個時候。我該如何診斷? (我是一個UNIX新手實際命令/路徑/協議!) –