【发布时间】: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