使用 libxml2/libxslt 的自訂安裝位置安裝 lxml 時遇到問題

使用 libxml2/libxslt 的自訂安裝位置安裝 lxml 時遇到問題

lxml我正在嘗試在運行 RHEL 的超級電腦上安裝調用我的帳戶的 python 模組。

我願意不是具有 root 存取權或超級使用者身分。

lxmllibxml2需要和的 dev/devel 版本,因為它們包含需要建置的libxslt頭檔。lxml但是超級電腦已將非開發版本安裝到其根目錄中,因此我透過從原始程式碼建置它們/usr將開發版本安裝到我的目錄中。home

兩者都構建順利,沒有拋出任何錯誤,並且所有必需的頭文件都在$HOME/usr/local/include/libxml2/libxml等待中。

但是,每當我嘗試時,它都會嘗試在根目錄中pip install lxml使用非 dev libxml2& :libxslt/bin

[myusername@q0144 ~]$ pip install --install-option="--prefix=$HOME/python_modules" lxml
... (some unimportant messages) ...
Building against libxml2/libxslt in the following directory: /usr/local/lib
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/local/include/libxml2 -I/tmp/pip_build_myusername/lxml/src/lxml/includes -I/N/soft/rhel6/python/2.7.3/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -w
In file included from src/lxml/lxml.etree.c:346:
/tmp/pip_build_myusername/lxml/src/lxml/includes/etree_defs.h:9:31: error: libxml/xmlversion.h: No such file or directory
/tmp/pip_build_myusername/lxml/src/lxml/includes/etree_defs.h:11:4: error: #error the development package of libxml2 (header files etc.) is not installed correctly
...(many more lines saying that the headers are missing, etc.)

還有幾十行表示開發包未正確安裝,因為它正在尋找錯誤的套件。

如何讓系統使用我安裝的libxml2/版本?libxslt

我甚至$HOME/bin首先$HOME/usr.cshrc.

為了確保涵蓋所有基礎,我還嘗試按照來源 tarball 中包含的文件lxml中的說明從原始碼建置:build.txt

[myusername@q0144 lxml-3.3.5]$ python setup.py build_ext -i -I $HOME/usr/include/libxml2/libxml --without-cython --with-xslt-config=$HOME/usr/local/bin/xslt-config
Building lxml version 3.3.5.
Building without Cython.
Using build configuration of libxslt 1.1.28
Building against libxml2/libxslt in the following directory: /usr/local/lib
/N/soft/rhel6/python/2.7.3/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'bugtrack_url'
warnings.warn(msg)
running build_ext
building 'lxml.etree' extension
gcc -pthread -fno-strict-aliasing -g -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -I/usr/local/include -I/usr/include/libxml2 -I/N/hd00/myusername/Quarry/python_modules/lxml-3.3.5/src/lxml/includes -I/N/u/myusername/Quarry/usr/include/libxml2/libxml -I/N/soft/rhel6/python/2.7.3/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml.etree.o -w
In file included from src/lxml/lxml.etree.c:346:0:
/N/hd00/rccaton/Quarry/python_modules/lxml-3.3.5/src/lxml/includes/etree_defs.h:
13:32: fatal error: libxslt/xsltconfig.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1

所以我基本上遇到了同樣的問題,/user/local/lib而不是我的$HOME/user等目錄。

我該如何解決這個問題?

答案1

確保bin兩個套件 (libxml2/libxslt) 的子目錄都位於您的PATH.它們包含*-config在編譯 lxml 期間使用的腳本來尋找 libxml2/libxslt 的安裝位置。

[pdobrogost@host /]$ echo $PATH
(...):/opt/libxslt-1.1.27/bin:/opt/libxml2-2.6.32/bin:(...)
[pdobrogost@host /]$ which xml2-config && which xslt-config
/opt/libxml2-2.6.32/bin/xml2-config
/opt/libxslt-1.1.27/bin/xslt-config

相關內容