Anaconda Jupyter运行requests_html报websockets无client属性错误
问题原因
AttributeError: module 'websockets' has no attribute 'client' 报错根因如下:
requests-html已多年未维护,仅适配9.x及更低版本的websockets库,高版本websockets重构了内部模块结构,调整了原有的client属性导入路径,因此触发报错- 你安装的
websocks-client是SOCKS代理相关的第三方包,和报错涉及的websockets库完全无关,无法解决问题
解决步骤
- 先卸载无关包和不兼容的高版本
websockets
pip uninstall websocks-client websockets -y
如果是Anaconda专属虚拟环境,也可以用conda命令卸载:
conda remove websocks-client websockets -y
- 安装
requests-html适配的websockets版本
为了避免安装到其他环境,你可以直接在运行代码的Jupyter Notebook单元格中执行以下命令,给当前Jupyter绑定的环境安装对应版本包:
import sys !{sys.executable} -m pip install websockets==9.1
- 安装完成后重启Jupyter内核,重新运行你的代码即可正常执行。
内容的提问来源于stack exchange,提问作者Ghbgon Gon
相关产品推荐
相关产品推荐

