我遇到了与这个 4 年前的帖子相同的错误:bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?
但我使用 MacOS、IntelliJ 和 Conda/Python 3 作为我的环境。我尝试过的事情:
$ STATIC_DEPS=true sudo pip install lxml
和
$ pip install -U lxml
Collecting lxml
Downloading https://files.pythonhosted.org/packages/16/31/be98027f5cd909e698210092ffc7d2e339492bc82cc872557b05f2ba3546/lxml-4.2.4-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (8.7MB)
100% |████████████████████████████████| 8.7MB 2.8MB/s
Installing collected packages: lxml
Found existing installation: lxml 4.1.1
Uninstalling lxml-4.1.1:
Successfully uninstalled lxml-4.1.1
Successfully installed lxml-4.2.4
之后:
$ python3 -m pip install lxml
Requirement already satisfied: lxml in /anaconda3/lib/python3.6/site-packages (4.2.4)
但是在 IntelliJ 中执行脚本时我仍然遇到相同的错误:
File "/Users/blabla/katalog-scanner/KatalogScanner.py", line 149, in <module>
soup = BeautifulSoup(html, 'lxml')
File "/anaconda3/envs/katalog-scanner/lib/python3.6/site-packages/bs4/__init__.py", line 198, 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?
我还尝试在代码中切换到 html5lib
,导致相同的错误,提示 html5lib
已请求但未找到。我还能尝试什么?
最佳答案
我的机器上安装了多个 Python,由
提供- 自制
- Anaconda
- 轻松安装
包管理器。我完全删除了 anaconda 实例(直接在我的 Macintosh-hd 下),删除了 easy_install 和 brew uninstall python --force
以删除我在 usr 中的所有 python 实例(2.7、3.6、3.7)/本地/bin
然后我只使用自制程序安装:brew install python3
然后你需要通过打开链接 python 和 pip 命令到 python3/pip3
~/.bash_profile
将其放在那里并保存:
alias python='python3'
alias pip='pip3'
然后刷新终端(也许您需要完全重新启动它甚至操作系统):
source ~/.bashrc
然后 python --version
应该显示最新的 3.x 版本,您应该能够执行以下操作:(第二个命令启动 python 解释器,第四个命令结束)
pip install beautifulsoup4
python
import bs4
exit()
现在您必须转到 IntelliJ > File > Project Structure 并将 Python 3.x SDK 添加到 Plattform Settings (SDK) 并将 Project Settings > Project SDK 设置为该 SDK
之前我也有一个 IntelliJ .iml 文件,但该项目似乎可以正常工作,无需
关于python - bs4.FeatureNotFound : . .. lxml 与 MacOS 和 Conda/Python 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52237938/