2011-05-12 179 views
5

我只需要一些不在主機上的軟件包(以及我和linux ......我們......我們沒有花太多時間在一起......)。如何在linux上沒有管理權限的情況下安裝lxml for python?

我用來安裝他們像:

# from the source 
python setup.py install --user 

# with easy_install 
easy_install prefix=~/.local package 

但它不與LXML工作。我在生成過程中得到了很多的錯誤:

x:~/lxml-2.3$ python setup.py build 
Building lxml version 2.3. 
Building without Cython. 
ERROR: /bin/sh: xslt-config: command not found 

** make sure the development packages of libxml2 and libxslt are installed ** 

Using build configuration of libxslt 
running build 
running build_py 
running build_ext 
building 'lxml.etree' extension 
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c src/lxml/lxml.etree.c -o build/temp.linux-i686-2.6/src/lxml/lxml.etree.o -w 
In file included from src/lxml/lxml.etree.c:227: 
src/lxml/etree_defs.h:9:31: error: libxml/xmlversion.h: No such file or directory 
src/lxml/etree_defs.h:11:4: error: #error the development package of libxml2 (header files etc.) is not installed correctly 
src/lxml/etree_defs.h:13:32: error: libxslt/xsltconfig.h: No such file or directory 
src/lxml/etree_defs.h:15:4: error: #error the development package of libxslt (header files etc.) is not installed correctly 
src/lxml/lxml.etree.c:230:29: error: libxml/encoding.h: No such file or directory 
src/lxml/lxml.etree.c:231:28: error: libxml/chvalid.h: No such file or directory 
src/lxml/lxml.etree.c:232:25: error: libxml/hash.h: No such file or directory 
... 
src/lxml/lxml.etree.c:55179: error: Б─≤xmlNodeБ─≥ undeclared (first use in this function) 
src/lxml/lxml.etree.c:55179: error: Б─≤__pyx_v_c_nodeБ─≥ undeclared (first use in this function) 
src/lxml/lxml.etree.c:55184: error: Б─≤_node_to_node_functionБ─≥ undeclared (first use in this function) 
src/lxml/lxml.etree.c:55184: error: expected Б─≤;Б─≥ before Б─≤__pyx_v_next_elementБ─≥ 
src/lxml/lxml.etree.c:55251: error: Б─≤struct __pyx_obj_4lxml_5etree__ReadOnlyProxyБ─≥ has no member named Б─≤_c_nodeБ─≥ 
... 

http://lxml.de/installation.html說,它有一定的相關性。但如何在沒有管理權限的情況下安裝它們

+0

你有沒有在virtualenv上試過這個? – karantan 2011-05-12 11:30:40

回答

12

如果你沒有管理員權限,無法說服安裝相關的包,爲你的管理員,你有兩個選擇:

選項1 - 下載源libxml2 and libxslt和編譯你的$HOME下進行安裝在某個地方,然後針對這些副本構建python-lxml。

這是一個非常相關的例子,因爲如果你錯過了更多的依賴關係,你可能會長時間下載/編譯。

選項2 - 下載與服務器上使用的Linux相同發行版的二進制包,並將內容解壓縮到您的主目錄下。

例如,如果你正在運行Ubuntu清醒,你會先找出你的操作系統正在使用的版本,然後下載你缺少的包:

% uname -m 
x86_64 
% aptitude show libxml2 | grep Version 
Version: 2.7.6.dfsg-1ubuntu1.1 

下一頁下載您需要的軟件包

% mkdir root ; cd root 
% wget http://us.archive.ubuntu.com/ubuntu/pool/main/libx/libxml2/libxml2_2.7.6.dfsg-1ubuntu1.1_amd64.deb 
% wget http://us.archive.ubuntu.com/ubuntu/pool/main/libx/libxslt/libxslt1.1_1.1.26-6build1_amd64.deb 
% wget http://us.archive.ubuntu.com/ubuntu/pool/main/l/lxml/python-lxml_2.2.4-1_amd64.deb 

將內容提取和合並的LXML天然和純Python代碼和移動至共享庫到頂部,然後取出所提取的內容:

從Ubuntu服務器直接0
% dpkg-deb -x libxml2_2.7.6.dfsg-1ubuntu1.1_amd64.deb . 
% dpkg-deb -x libxslt1.1_1.1.26-6build1_amd64.deb . 
% dpkg-deb -x python-lxml_2.2.4-1_amd64.deb . 
% mv ./usr/lib/python2.6/dist-packages/lxml . 
% mv ./usr/share/pyshared/lxml/* lxml 
% mv ./usr/lib . 
% rm *.deb 
% rm -rf usr 

最後,要使用這些文件,您需要將LD_LIBRARY_PATH和PYTHONPATH環境變量設置爲指向$HOME/root。將這些在你~/.bashrc(或同等),所以它們是永久的:

% export LD_LIBRARY_PATH=$HOME/root/lib 
% export PYTHONPATH=$HOME/root 

您可以驗證共享庫正在使用中發現ldd(如果它安裝):

% ldd $HOME/root/lxml/etree.so | grep $HOME 
libxslt.so.1 => /home/user/root/lib/libxslt.so.1 (0x00007ff9b1f0f000) 
libexslt.so.0 => /home/user/root/lib/libexslt.so.0 (0x00007ff9b1cfa000) 
libxml2.so.2 => /home/user/root/lib/libxml2.so.2 (0x00007ff9b19a9000) 

那麼你準備測試Python:

% python 
>>> from lxml import etree 
+0

我在debian上。謝謝,我會嘗試。 – CSZ 2011-05-13 01:35:12

+0

它的工作原理,再次感謝詳細的描述。 – CSZ 2011-05-13 03:35:56

+0

很高興聽到它,與您的應用程序祝你好運! – samplebias 2011-05-13 03:49:13

相關問題