venv error bs4.FeatureNotFound: Couldn‘t find a tree builder with the features you requested: lxml.

场景

在Windows系统上,使用 pycharm 运行自己的github项目https://github.com/birdflyi/db_engines_ranking_table_crawling 的clone 副本(确信在redhat上可执行),在语句 `soup = BeautifulSoup(response_body, 'lxml')` 处发生以下错误:

File "D:\github_repo\db_engines_ranking_table_crawling\venv\lib\site-packages\bs4\__init__.py", line 248, in __init__
    raise FeatureNotFound(
bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library?

原因

未安装`lxml`,import ssl 也发生加载DLL找不到指定的模块错误。

import _ssl # if we can't import it, let the error propagate

ImportError: DLL load failed while importing _ssl: The specified module could not be found.

查阅资料发现venv中缺少的dll:

libcrypto-1_1-x64.dll
libssl-1_1-x64.dll

解决办法(不改动代码的方式)

*注:改动代码的方式可尝试built in python html parser:`soup = BeautifulSoup(s, "html.parser")`,详见python - bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: lxml. Do you need to install a parser library? - Stack Overflow

不改动代码的方式:

Step1: 安装`lxml`

pip install lxml

  尝试运行,若仍不能执行进入Step2.

Step2: 放入dll

  需要的dll:libcrypto-1_1-x64.dll 和 libssl-1_1-x64.dll

  可以在 “C:\Windows\System32” 下使用搜索功能查找上述两个文件,通常在drivers或者DriverStore文件夹或子文件夹下。

若系统中无相应的dll:

  安装`openssl`:Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

  找到以上两个dll。

放入anaconda中:

  在anaconda的安装目录中搜索 `_ssl.pyd` 的路径,我的路径如下:

D:\ProgramData\Anaconda3\DLLs
D:\ProgramData\Anaconda3\pkgs\python-3.9.13-h6244533_1\DLLs

  将以上两个dll文件放在`D:\ProgramData\Anaconda3\pkgs\python-3.9.13-h6244533_1\DLLs`下,或者每个下面都丢一份;

  进入pycharm中删除venv,按提示添加interpreter,查看`venv\Scripts\`下是否自动放入了以上两个dll,若未找到,可以手动放入dll;

  将requirements和Step1中的lxml包都安装好,尝试运行即可。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bird_fly_i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值