Phil
Phil

Reputation: 7566

bs4.FeatureNotFound: ... lxml with MacOS and Conda / Python 3

I am getting the same error as in this 4 years old thread: bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

But I am using MacOS, IntelliJ and Conda / Python 3 as my environment. Things I have tried:

$ STATIC_DEPS=true sudo pip install lxml

and

$ 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

after that:

$ python3 -m pip install lxml
Requirement already satisfied: lxml in /anaconda3/lib/python3.6/site-packages (4.2.4)

But I still get the same error upon executing my script in 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?

I also tried switching to html5lib in my code, resulting in the same error, saying that html5lib was requested and not found. What else can I try?

Upvotes: 1

Views: 808

Answers (1)

Phil
Phil

Reputation: 7566

I had multiple installations of Python on my machine, provided by

  • homebrew
  • Anaconda
  • easy_install

package managers. I deleted the anaconda instance completely (was directly under my macintosh-hd), removed easy_install and brew uninstall python --force to remove all the instances of python (2.7, 3.6, 3.7) I had in usr/local/bin

then I installed only with homebrew: brew install python3

then you need to link python and pip commands to python3/pip3 by opening

~/.bash_profile

putting this there and saving:

alias python='python3'
alias pip='pip3'

then refresh the terminal (maybe you need to restart it completely or even the OS):

source ~/.bashrc

then python --version should show the newest 3.x version an you should be able to do: (second command starts python interpreter, fourth ends it)

pip install beautifulsoup4
python
import bs4
exit()

Now you have to go to IntelliJ > File > Project Structure and add Python 3.x SDK to Plattform Settings (SDK) and set Project Settings > Project SDK to that SDK

Before I also had an IntelliJ .iml-file, but the project seems to work fine without

Upvotes: 1

Related Questions