【问题标题】:Python-Failure to import BeautifulSoup4 in Python3.3.1, but success in Python 2.7-Installed using easy_installPython - 在 Python3.3.1 中导入 BeautifulSoup4 失败,但在 Python 2.7 中成功 - 使用 easy_install 安装
【发布时间】:2013-07-15 13:06:53
【问题描述】:

背景和我所做的:我正在编写一个网页内容提取器,并意识到需要安装 BeautifulSoup4 以更好地解析我的 HTML 文件。在我的 Ubuntu 13.04 机器上,我安装了 Python2.7(系统默认)和 Python3.3.1。由于“SSL 证书”问题,pip 和 easy_install 都出现了几次失败后,我最后一次尝试使用 easy_install 安装 BeautifulSoup4。

但是:看来easy_install将BS4安装到我系统的Python2.7目录(/usr/local/lib/python2.7/dist-packages)中,从以下信息可以看出:

Searching for beautifulsoup4
Reading http://pypi.python.org/simple/beautifulsoup4/
Best match: beautifulsoup4 4.2.1
Downloading https://pypi.python.org/packages/source/b/beautifulsoup4/beautifulsoup4-4.2.1.tar.gz#md5=91ea70ce16a5f1f43e58f2ef05651679
Processing beautifulsoup4-4.2.1.tar.gz
Writing /tmp/easy_install-OLXNjV/beautifulsoup4-4.2.1/setup.cfg
Running beautifulsoup4-4.2.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-OLXNjV/beautifulsoup4-4.2.1/egg-dist-tmp-SpupH8
zip_safe flag not set; analyzing archive contents...
Adding beautifulsoup4 4.2.1 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/beautifulsoup4-4.2.1-py2.7.egg 

现在我可以在 Python2.7 中导入 BS4,但不能在 Python3.3 中导入,并显示以下错误消息:

>>> import bs4
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    import bs4
ImportError: No module named 'bs4'  

问题:我应该将这个 Python2.7 目录添加到我的 Python3.3 库目录吗? (由于这个共享库路径,我担心同一模块的不同版本将来会发生冲突)或者我应该卸载 BS4 并使用pip 再次尝试,所以它可能会在 Python3.3 目录中安装 BS4? (现在,当我尝试使用pip:Requirement already satisfied (use --upgrade to upgrade): beautifulsoup4 in ./beautifulsoup4-4.2.1-py2.7.egg 再次安装 BS4 时,返回此问题)有关解决此问题的其他一般指示也将不胜感激。谢谢!

【问题讨论】:

    标签: python module beautifulsoup easy-install library-path


    【解决方案1】:

    根据official homepage 上的Download Beautiful Soup 部分,您可以在Ubuntu 13.04 上安装python-beautifulsoup4 软件包。

    尝试这样做以防止 Python 2.7 和 3.3 之间的冲突。不过,在你这样做之前,我建议删除 Beautiful Soup egg 以避免潜在的版本冲突。

    【讨论】:

      猜你喜欢
      • 2011-10-10
      • 1970-01-01
      • 1970-01-01
      • 2015-04-01
      • 2016-06-26
      • 2015-03-27
      • 2015-12-12
      • 1970-01-01
      • 2014-01-04
      相关资源
      最近更新 更多