...
soup = BeautifulSoup(html, "lxml")
File "/Library/Python/2.7/site-packages/bs4/__init__.py", line 152, in __init__
% ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
Run Code Online (Sandbox Code Playgroud)
以上输出在我的终端上.我在Mac OS 10.7.x上.我有Python 2.7.1,并按照本教程获得Beautiful Soup和lxml,它们都已成功安装并使用位于此处的单独测试文件.在导致此错误的Python脚本中,我包含了这一行:
from pageCrawler import comparePages
在pageCrawler文件中,我包含以下两行:
from bs4 import BeautifulSoup
from urllib2 import urlopen
任何有关确定问题是什么以及如何解决问题的帮助都将不胜感激.
我发现Linux发行版的现有Python文档非常出色.对于Windows ......不是那么多.我已经配置好我的Linux系统,但我需要一些帮助才能准备好Windows 8.1平板电脑.
我的项目需要Python 3.4的lxml模块.我发现了很多关于如何安装lxml的教程,但每个教程都失败了.
https://docs.python.org/3/installing/ 我已经下载了"get-pip.py"并成功地从Windows cmd行运行了它,结果如下:
Requirement already up-to-date: pip in c:\python34\lib\site-packages
Run Code Online (Sandbox Code Playgroud)
所以我认为我没有"点"问题.从那里我从Windows cmd行运行以下命令:
python -m pip install lxml
Run Code Online (Sandbox Code Playgroud)
一长串命令滚动,但有几行似乎是我无法解决的错误.
ERROR: b"'xslt-config' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"
** make sure the development packages of libxml2 and libxslt are installed **
Run Code Online (Sandbox Code Playgroud)
和
Failed building wheel for lxml
Run Code Online (Sandbox Code Playgroud)
最后一部分都是红色的
Command "C:\Python34\python.exe -c "import setuptools, tokenize;__file__='C:\\Users\\Owner\\AppData\\Local\\Temp\\pip-build-ya3n6wkd\\lxml\\setup.py';exec(compi
le(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record C:\Users\Owner\AppData\Local\Temp\pip-ytybzl9l-r
ecord\install-record.txt --single-version-externally-managed --compile" failed with error code …Run Code Online (Sandbox Code Playgroud) 我在mac 10.7.5上使用python 2,7.5,beautifulsoup 4.2.1.我将使用lxml库解析xml页面,如beautifulsoup教程中所述.但是,当我运行我的代码时,它会显示出来
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested:
lxml,xml. Do you need to install a parser library?
Run Code Online (Sandbox Code Playgroud)
我确信我已经通过所有方法安装了lxml:easy_install,pip,port等.我试着在我的代码中添加一行,看看是否安装了lxml:
import lxml
Run Code Online (Sandbox Code Playgroud)
然后python可以成功浏览此代码并再次显示上一条错误消息,发生在同一行.
所以我很确定已经安装了lxml,但没有正确安装.所以我决定卸载lxml,然后使用'正确'方法重新安装.但是当我输入时
easy_install -m lxml
Run Code Online (Sandbox Code Playgroud)
表明:
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, …Run Code Online (Sandbox Code Playgroud)