Linux下Python XML库lxml的安装


要用python处理XML数据,由于之前用过lxml,因此打算采用lxml库。找出原来的写好的脚本发现不能运行,没有lxml模块,看来得自己动手。记得原来用的时候模似安装挺简单的啊,这次貌似不怎么幸运。按照google的结果,好几次都没成功。

本人系统是Ubuntu 12.04,后来知道可以直接sudo apt-get install python-lxml就可以。现在想起,我安装的时候,试过sudo apt-get install lxml,提示找不到包。这里引出一个问题如何根据关键词查询包名。

我用sudo apt-get help(好多这种格式的命令都会支持help),结果没有发现apt-get提供的根据关键词搜索包名的command或者option。谷歌之后找到了解决这个小问题的方法:先用 apt-cache search找到软件的准确名字,再用apt-cache show来看详细的信息。

apt-cache search lxml
结果:
inkscape - vector-based drawing program
python-lxml - pythonic binding for the libxml2 and libxslt libraries
python-lxml-dbg - pythonic binding for the libxml2 and libxslt libraries (debug extension)
python-lxml-doc - pythonic binding for the libxml2 and libxslt libraries (documentation)
python3-lxml - pythonic binding for the libxml2 and libxslt libraries
python3-lxml-dbg - pythonic binding for the libxml2 and libxslt libraries (debug extension)
xml-core - XML infrastructure and XML catalog file support
python-okasha - trivial WSGI web framework for Python
python-pyquery - jQuery-like library for python
tclxml - Tcl library for XML parsing
然后就可以用apt-cache python-lxml来查看包的依赖等详细信息。

顺便查了一下apt-cache的用法,贴在下面:

apt-cache是一个apt软件包管理工具,它可查询apt的二进制软件包缓存文件。通过它我们可查询软件包的状态信息。
apt-cache show package_name
显示软件的信息,包括版本号,安装状态和包依赖关系等。
apt-cache search package_name
搜索软件包,可用正则表达式。
apt-cache showpkg package_name
显示软件包的依赖关系信息。
apt-cache policy package_name
显示软件包的安装状态和版本信息。
apt-cache depends package_name
显示指定软件包所依赖的软件包。
apt-cache rdepends package_name
显示软件包的反向依赖关系,即有什么软件包需依赖你所指定的软件包。

相关内容