如何在没有管理权限的情况下为linux安装lxml for python?

CSZ*_*CSZ 5 python linux lxml

我只需要一些不在主机上出现的软件包(我和linux ......我们......我们没有花太多时间在一起......).

我过去经常安装它们:

# from the source
python setup.py install --user
Run Code Online (Sandbox Code Playgroud)

要么

# with easy_install
easy_install prefix=~/.local package
Run Code Online (Sandbox Code Playgroud)

但它不适用于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???
...
Run Code Online (Sandbox Code Playgroud)

http://lxml.de/installation.html表示它有一些依赖关系.但如何安装它们没有管理权限?

sam*_*ias 11

如果您没有管理员权限,并且无法说服管理员为您安装相关软件包,则有两种选择:

选项1 - 下载源代码libxml2并在libxslt其中编译和安装它们$HOME,然后针对这些副本构建python-lxml.

这是一个非常复杂的示例,因为如果您缺少其他依赖项,则可能需要长时间下载/编译.

选项2 - 下载服务器上使用的相同Linux发行版的二进制包,并提取主目录下的内容.

例如,如果你正在运行Ubuntu Lucid,你首先要找出你的操作系统正在使用的版本,然后下载你缺少的软件包:

% uname -m
x86_64
% aptitude show libxml2 | grep Version
Version: 2.7.6.dfsg-1ubuntu1.1
Run Code Online (Sandbox Code Playgroud)

接下来,直接从Ubuntu服务器下载所需的软件包:

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

提取内容并合并lxml native和pure-python代码并将共享库移到顶部,然后删除提取的内容:

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

最后,要使用这些文件,您需要将LD_LIBRARY_PATH和PYTHONPATH环境变量设置为指向$HOME/root.将它们放在你的~/.bashrc(或同等的)中,这样它们就是永久性的:

% export LD_LIBRARY_PATH=$HOME/root/lib
% export PYTHONPATH=$HOME/root
Run Code Online (Sandbox Code Playgroud)

您可以使用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)
Run Code Online (Sandbox Code Playgroud)

然后你就可以测试Python:

% python
>>> from lxml import etree
Run Code Online (Sandbox Code Playgroud)