首页 > 解决方案 > ModuleNotFoundError:即使在安装和重新安装后也没有名为“bs4”的模块

问题描述

我正在尝试运行我的 Python 文件。(py名称.py)

    from bs4 import BeautifulSoup as BS
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\bs4\__init__.py", line 29, in <module>
    from .builder import builder_registry
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\bs4\builder\__init__.py", line 294, in <module>
    from . import _htmlparser
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\bs4\builder\_htmlparser.py", line 7, in <module>
    from html.parser import (
ImportError: cannot import name 'HTMLParseError' from 'html.parser' (C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\html\parser.py)

我使用“pip”安装了这个库。完全删除并重新安装该库后,运行此代码时会出现此错误。

  File "name.py", line 9, in <module>
from bs4 import BeautifulSoup as BS
ModuleNotFoundError: No module named 'bs4'

标签: pythonpython-3.xbeautifulsoup

解决方案


我解决了这个问题。首先,我从我的电脑中删除了所有提到的 BS4。然后在 CMD 中移动路径:

C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Scripts.

并在那里花费了命令:

pip install beautifulsoup4


推荐阅读