代码之家  ›  专栏  ›  技术社区  ›  Phil

bs4.FeatureNotFound:…使用MacOS和Conda/Python 3的lxml

  •  1
  • Phil  · 技术社区  · 6 年前

    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/python3作为我的环境。我尝试过的事情:

    $ 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 在我的代码中,导致了同样的错误 已请求但未找到。我还能试什么?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Phil    6 年前

    我的机器上安装了多个Python,由

    • 自制
    • 水蟒
    • 易于安装

    包管理器。我完全删除了anaconda实例(直接在我的macintosh hd下),删除了easy\u安装 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添加到Plattform Settings(SDK)中,并将Project Settings>Project SDK设置为该SDK

    之前,我也有一个IntelliJ.iml文件,但项目似乎工作良好,没有