我得到了与这个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实例(直接在我的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'
然后刷新终端(可能需要完全重启它甚至是OS):
source ~/.bashrc
然后python --version
应该显示你应该能够做的最新3.x版本:(第二个命令启动python解释器,第四个命令结束)
pip install beautifulsoup4
python
import bs4
exit()
现在你必须转到IntelliJ>文件>项目结构并将Python 3.x SDK添加到Plattform设置(SDK)并将项目设置>项目SDK设置为该SDK
之前我还有一个IntelliJ .iml文件,但该项目似乎没有正常工作