我遇到了与这个已有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
却未找到。我还能尝试什么?
答案 0 :(得分:1)
我在计算机上安装了多个python,由
提供软件包管理器。我完全删除了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>文件>项目结构,并将Python 3.x SDK添加到平台设置(SDK),然后将项目设置>项目SDK设置为该SDK
之前我也有一个IntelliJ .iml文件,但是该项目在没有该文件的情况下似乎可以正常工作