歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Linux下Python XML庫lxml的安裝

Linux下Python XML庫lxml的安裝

日期:2017/3/1 9:55:23   编辑:Linux編程

要用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
顯示軟件包的反向依賴關系,即有什麼軟件包需依賴你所指定的軟件包。

更多Ubuntu相關信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2

Copyright © Linux教程網 All Rights Reserved