Python 版本和使用的设备
- 蟒蛇 2,7.5
- Mac 10.7.5
- 美丽汤 4.2.1。
我正在关注 BeautifulSoup 教程,但是当我尝试使用 lxml 库解析 xml 页面时,出现以下错误:
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested:
lxml,xml. Do you need to install a parser library?
我确定我已经通过所有方法安装了 lxml:easy_install、pip、port 等。我尝试在我的代码中添加一行以查看是否安装了 lxml:
import lxml
然后 python 可以成功地遍历这段代码并再次显示前面的错误消息,发生在同一行。
所以我很确定 lxml 已安装,但未正确安装。所以我决定卸载 lxml,然后使用“正确”的方法重新安装。但是当我输入
easy_install -m lxml
我收到以下错误:
Searching for lxml
Best match: lxml 3.2.1
Processing lxml-3.2.1-py2.7-macosx-10.6-intel.egg
Using /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/lxml-
3.2.1-py2.7-macosx-10.6-intel.egg
Because this distribution was installed --multi-version, before you can
import modules from this package in an application, you will need to
'import pkg_resources' and then use a 'require()' call similar to one of
these examples, in order to select the desired version:
pkg_resources.require("lxml") # latest installed version
pkg_resources.require("lxml==3.2.1") # this exact version
pkg_resources.require("lxml>=3.2.1") # this version or higher
Processing dependencies for lxml
Finished processing dependencies for lxml
所以我不知道如何继续卸载,我在谷歌上查找了很多关于这个问题的帖子,但我仍然找不到任何有用的信息。
这是我的源代码
import mechanize
from bs4 import BeautifulSoup
import lxml
class count:
def __init__(self,protein):
self.proteinCode = protein
self.br = mechanize.Browser()
def first_search(self):
#Test 0
soup = BeautifulSoup(self.br.open("http://www.ncbi.nlm.nih.gov/protein/21225921?report=genbank&log$=prottop&blast_rank=1&RID=YGJHMSET015"), ['lxml','xml'])
return
if __name__=='__main__':
proteinCode = sys.argv[1]
gogogo = count(proteinCode)
问题
- 如何卸载 lxml?
- 如何“正确”安装 lxml?我怎么知道它安装正确?