【问题标题】:Why do I get an ImportError when I try to import the beautifulsoup module? Can somebody help, please?当我尝试导入 beautifulsoup 模块时,为什么会收到 ImportError?有人可以帮忙吗?
【发布时间】:2021-10-03 03:25:20
【问题描述】:

当我使用代码“from bs4 import beautifulsoup as bs”时,我得到以下 ImportError: ImportError with a directory: cannot import name 'BeautifulSoup4' from 'bs4' (C:\Users........ .anaconda3\lib\site-packages\bs4_init_.py)

【问题讨论】:

  • 您尝试过什么解决问题的方法?你的问题没有重点。已经有大量类似的类型可用。标记要关闭的问题。
  • 这能回答你的问题吗? ImportError: No module named requests

标签: python anaconda


【解决方案1】:

你已经安装了beautifulsoup4 模块吗? 如果不是请先安装模块..

pip install beautifulsoup4

【讨论】:

  • 是的,我确实安装了它并重新启动了我的计算机。
  • @AnsumanaKorleh 好的尝试现在正确导入from bs4 import BeautifulSoup as bs
【解决方案2】:
  • 确保该模块已安装。
>>> import bs4

如果模块没有安装,你会看到这个错误ModuleNotFoundError

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'bs4'
>>>                                                                                                                  
  • 使用 pip 安装模块
pip install beautifulsoup4
  • 正确导入模块..
from bs4 import BeautifulSoup as bs

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 2021-06-20
    • 2015-06-17
    • 2022-12-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多