我在mac 10.7.5上使用python 2,7.5,beautifulsoup 4.2.1。我将使用lxml库解析xml页面,正如beautifulsoup教程中所教导的。然而,当我跑我的代码,它显示如何重新安装lxml?
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的,画中画,端口等我试着添加一行到我的代码,看看是否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?我如何知道它已正确安装?
在相关问题的建议(http://stackoverflow.com/questions/14153221/removed-macports-now-python-is-broken)卸载并重新安装解决了我的问题。 –
由于'lxml'在我的机器上缺失,执行'sudo pip install lxml'解决了我的问题。 –
此外,安装lxml时,此步骤可能也是必要的:http://stackoverflow.com/questions/19548011/cannot-install-lxml-on-mac-os-x-10-9 – taylorc93