【问题标题】:python modules BeautifulSoup importErrorpython模块BeautifulSoup importError
【发布时间】:2016-12-12 14:26:24
【问题描述】:

我的设备是 Kubuntu 14.04 桌面版 - VPS OVH。我正在使用 Python 2.7。

我想导入BeautifulSoup

from bs4 import BeautifulSoup

但是,我有这个错误:

ImportError: No module named bs4

我已经安装了BeautifulSoup。我已将该模块直接复制到我的应用程序文件夹中,BeautifulSoup 有效。我想在我的应用程序文件夹中没有BeautifulSoup 文件夹来运行我的应用程序。

【问题讨论】:

    标签: python linux python-2.7 beautifulsoup


    【解决方案1】:

    不要将BeautifulSoup 文件夹复制到您的工作目录,而是尝试使用以下命令直接安装它:

    pip install beautifulsoup4
    

    【讨论】:

    • 我正在尝试,但它不起作用。 Python 没有看到所有 pip 库。
    • "ImportError: No module named bs4" - 但我已经安装了这个模块。
    • 你运行pip install beautifulsoup4了吗?当你运行pip freeze 时,你得到了什么?
    • 也许你的包是为你机器上的另一个 python 解释器安装的!
    【解决方案2】:

    如果您想直接访问它,请使用

    pip install beautifulsoup4
    

    或者您可以将 BeautifulSoup 存储在一个文件夹中,然后您可以通过在该文件夹及其包含的所有子文件夹中创建 __init__.py 文件将其作为一个包,在您的情况下,它才会被视为一个包在当前工作目录的文件夹中创建 __init__.py 文件,然后将 BeautifulSoup 放入其中并尝试

    from <folder_name> import BeautifulSoup
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-31
      • 1970-01-01
      • 2015-01-02
      • 2012-10-04
      • 2019-12-12
      • 2011-11-27
      • 2017-12-21
      • 1970-01-01
      相关资源
      最近更新 更多