注目キーワード
  1. 技術
  2. 広告
  3. IDFA
  4. PHP
  5. WordPress

bs4.FeatureNotFound: Couldn’t find a tree builder with the features you requested: lxml. と表示されたときの対処法(python)

概要

pythonでクローリングプログラムを作ったところ、BeautifulSoupにおいて、bs4の実行エラーが出たので、そのときの対応をメモします。

下記のようなエラーが出ました。

$ python sample.py
Traceback (most recent call last):
  File "sample.py", line xx, in <module>
    main()
  File "sample.py", line xx, in main
    soup = BeautifulSoup(page_url,"lxml")
  bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

対応

lxmlのインストールが必要なため、依存パッケージであるlxmlをインストールします。

$ pip install lxml
Collecting lxml
  Downloading lxml-4.5.2-cp27-cp27m-macosx_10_9_x86_64.whl (4.4 MB)
     |████████████████████████████████| 4.4 MB 4.8 MB/s
Installing collected packages: lxml
Successfully installed lxml-4.5.2

確認

以下のコマンドで確認します。

$ python -m pip freeze | grep lxml
lxml==4.5.2

インストールされているのが確認できました。