日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

在Linux服务器上安装lxml

發(fā)布時間:2023/12/19 综合教程 36 生活家
生活随笔 收集整理的這篇文章主要介紹了 在Linux服务器上安装lxml 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近新接的活,第一個任務是處理一堆xml格式的專利文件,把里面的有效信息提取出來

因為公司的相關規(guī)定不允許把文件down到本地處理,只能在對方提供的遠程服務器上寫代碼

由于xml里面的元素是XXX:YYYY這種帶前綴的格式,用xml.etree的ElementTree死活解析不出來,最后從OverStack上找到了解釋

ElementTree is not too smart about namespaces. You need to give the.find(),findall()anditerfind()methods an explicit namespace dictionary. This is not documented very well:

namespaces = {'owl': 'http://www.w3.org/2002/07/owl#'} # add more as needed

root.findall('owl:Class', namespaces)

Prefixes areonlylooked up in thenamespacesparameter you pass in. This means you can use any namespace prefix you like; the API splits off theowl:part, looks up the corresponding namespace URL in thenamespacesdictionary, then changes the search to look for the XPath expression{http://www.w3.org/2002/07/owl}Classinstead.

If you can switch to thelxmllibrarythings are better; that library supports the same ElementTree API, but collects namespaces for you in a.nsmapattribute on elements.

于是果斷去裝lxml

服務器上已經裝了python2.7,然而除此之外的東西全都沒有,因此又手動裝了pip

執(zhí)行pip install lxml 報了一大堆錯,注意到:

Could not find function xmlCheckVersion in library libxml2. Is libxml2 installed?

查到lxml還需要先安裝依賴庫libxml2和libxslt的開發(fā)版

yum install libxml2-devel

yum install libxslt-devel

安裝好依賴庫后pip還是報錯

這次又認真讀了一遍錯誤信息發(fā)現前面居然還有一行:

unable to execute gcc: No such file or directory

好吧,連gcc都沒有安裝,難怪無法編譯

yum install gcc

安裝好以后pip install,居然,還是報錯!

src/lxml/lxml.etree.c:84:20: 致命錯誤:Python.h:沒有那個文件或目錄

再查資料,原來還需要安裝一個python-devel,這是Python的頭文件和靜態(tài)庫包

yum install python-devel

安裝完之后再次pip install lxml

終于見到了喜聞樂見的

Successfully installed lxml

至此,linux下的lxml安裝完成

今日事今日畢

總結

以上是生活随笔為你收集整理的在Linux服务器上安装lxml的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。