bs4.FeatureNotFound: ... lxml 与 MacOS 和 Conda / Python 3
Posted
技术标签:
【中文标题】bs4.FeatureNotFound: ... lxml 与 MacOS 和 Conda / Python 3【英文标题】:bs4.FeatureNotFound: ... lxml with MacOS and Conda / Python 3 【发布时间】:2019-02-13 17:11:32 【问题描述】:我在这个 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
被请求但未找到。我还能尝试什么?
【问题讨论】:
我认为你需要使用 Conda 来进行安装,试试conda install lxml
【参考方案1】:
我的机器上安装了多个 Python,由
提供 自制软件 蟒蛇 easy_install包管理器。我完全删除了anaconda实例(直接在我的macintosh-hd下),删除了easy_install和brew uninstall python --force
以删除我在usr/local/bin中的所有python实例(2.7、3.6、3.7)
然后我只用自制软件安装: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 添加到 Platform Settings (SDK) 并将 Project Settings > Project SDK 设置为该 SDK
之前我也有一个 IntelliJ .iml 文件,但是没有这个项目似乎可以正常工作
【讨论】:
以上是关于bs4.FeatureNotFound: ... lxml 与 MacOS 和 Conda / Python 3的主要内容,如果未能解决你的问题,请参考以下文章
安装 lxml 后“bs4.FeatureNotFound:找不到具有您请求的功能的树生成器:lxml”
bs4.FeatureNotFound:找不到具有您请求的功能的树生成器:lxml。您需要安装解析器库吗?
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you
运行爬虫遇到奇葩的问题 bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml.