【问题标题】:BeautifulSoup and lxml in Jupyter notebookJupyter 笔记本中的 BeautifulSoup 和 lxml
【发布时间】:2016-07-27 21:48:54
【问题描述】:

我在为 jupyter 笔记本提供服务的 Docker 容器中运行 BeautifulSoup 和 lxml 时遇到问题。

我已经通过sudo pip install lxml 安装了 lxml,如果我运行一个交互式 python 解释器,一切正常:

    >>> from bs4 import BeautifulSoup as bs
    >>> bs('test','lxml')
    <html><body><p>test</p></body></html>

如果我在 Jupyter 笔记本中运行相同的代码,则会出现以下错误

    FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml.

sys.executable 在这两种情况下都返回/opt/ds/bin/python3。

非常感谢任何帮助!

【问题讨论】:

  • 解释器用python或python3打开。似乎 Jupyter 运行 python3。你跑sudo pip3 install lxml了吗?
  • 一切都是用python3运行的,确实也是pip。
  • 直接导入有效吗? import bs4.builder._lxml 和 from lxml import etree ?

标签: python beautifulsoup lxml jupyter


【解决方案1】:

我有同样的问题。保存,关闭并再次打开程序,现在它工作正常,不需要额外的导入语句。我的猜测是 Restart and Run All 也会做同样的事情。基本上内核(我正在运行一个 jupyter notebook)必须重新启动才能使用我刚刚使用 pip 安装的 lxml。

【讨论】:

    猜你喜欢
    • 2022-01-04
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-18
    • 2019-05-10
    相关资源
    最近更新 更多