【问题标题】:Couldn't find a tree builder with the features you requested: xml找不到具有您请求的功能的树生成器:xml
【发布时间】:2019-11-07 06:34:57
【问题描述】:

我安装了 anaconda,下面是在 jupyter notebook 中完美运行的代码。

from bs4 import BeautifulSoup as bs

xml = '<head><body></body></head>'
s = bs(xml,'xml')
print(s)

输出:

<?xml version="1.0" encoding="utf-8"?>
<Head><body/></Head>

但如果我尝试使用 windows 命令提示符运行相同的代码,则会引发以下错误:

F:\ProgramData\Anaconda3>python testcode.py Traceback(最近 最后调用):文件“testcode.py”,第 4 行,在 s = bs(xml,'xml') 文件“F:\ProgramData\Anaconda3\lib\site-packages\bs4__init__.py”,行 198,在初始化 % ",".join(features)) bs4.FeatureNotFound:找不到具有您请求的功能的树构建器 d:xml。是否需要安装 解析器库?

我什至尝试将脚本复制到“F:\ProgramData\Anaconda3”文件夹并从这里运行命令提示符。但同样的错误。

注意:F: 是操作系统驱动器。

我该如何解决这个问题?

运行 python 脚本的根目录(在 anaconda windows 上)应该是什么,以便它可以找到 conda 包?

关于从该位置运行 python 控制台的一些观察:

F:\ProgramData\Anaconda3>python
Python 3.7.0 (default, Jun 28 2018, 08:04:48) [MSC v.1912 64 bit (AMD64)] :: Ana
conda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import xml
>>> from bs4 import BeautifulSoup as bs
>>> s = bs("<head></head>","xml")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "F:\ProgramData\Anaconda3\lib\site-packages\bs4\__init__.py", line 198, i
n __init__
    % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requeste
d: xml. Do you need to install a parser library?
>>> import lxml
>>> s = bs("<head></head>","lxml")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "F:\ProgramData\Anaconda3\lib\site-packages\bs4\__init__.py", line 198, i
n __init__
    % ",".join(features))
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requeste
d: lxml. Do you need to install a parser library?
>>>

更新:

我从 Python exe 安装程序在新的 Windows 操作系统上安装了 3.7.3 64 位 Python,将 python 路径添加到环境变量,使用 pip 安装了 bs4、lxml。现在它起作用了。

但我仍然想知道如何使 anaconda 安装足够,足以让 python 脚本在系统中的任何位置运行。

Anaconda安装后缺少什么,只是路径变量还是还有其他东西??

【问题讨论】:

  • 尝试使用lxml 而不是xml
  • @bharatk xmllxml 的错误相同。而且我不想使用lxml,因为我希望标签区分大小写并保留大小写。

标签: python windows beautifulsoup anaconda python-3.7


【解决方案1】:

Anaconda 支持多种环境。默认环境是“基础(根)”。从那里打开终端,您就可以开始了。

如果你从没有安装lxml库的其他环境打开终端,你会遇到描述中提到的问题。

【讨论】:

    猜你喜欢
    • 2018-06-14
    • 2017-02-20
    • 2020-07-02
    • 2017-02-28
    • 2017-11-17
    • 2020-07-09
    • 1970-01-01
    • 2019-05-16
    相关资源
    最近更新 更多