【问题标题】:BeautifulSoup import error in Python3.3Python3.3 中的 BeautifulSoup 导入错误
【发布时间】:2013-06-20 05:47:50
【问题描述】:

Python 才一周。我已经使用 easy_install 安装了 BeautifulSoup4。安装似乎没问题,因为在 Python shell 中并使用 from bs4 import BeautifulSoup 时没有错误。

尝试在我从 win7 上的 cmd 控制台调用的脚本中使用“from bs4 import BeautifulSoup”时出现错误“python C:\Users\Ryan\Desktop\precipitation.py”

从 bs4 导入 BeautifulSoup

#precipitation.py:

import urllib.request
import re
from bs4 import BeautifulSoup


#htmlfile = urllib.request.urlopen("http://www.wunderground.com/history/airport/KYIP/2013/6/16/DailyHistory.html6")
#htmltext = htmlfile.read()
#regex = b'<td class="indent"><span>Precipitation</span></td>\n<td><span class="nobr"><span class="b">(.+?)</span>''
#pattern = re.compile(regex)

print('Who made the Soup?!')

运行脚本时出错: python C:\Users\Ryan\Desktop\precipitation.py

Traceback (most recent call last):
File "C:\Users\Ryan\Desktop\precipitation.py", line 3, in
    from bs4 import BeautifulSoup
File "C:\Users\Ryan\Desktop\precipitation.py", line 1, in <module>
    from bs4 import BeautifulSoup
ImportError: cannot import name BeautifulSoup

【问题讨论】:

  • 这是您收到的确切错误消息吗?您确定您的桌面上没有文件bs4.py 吗? (除了一个文件名,您的错误看起来就像您在桌面上使用文件 bs4 时遇到的错误)
  • 正确。我在桌面上创建了一个文件 bs4.py 来搞乱 BS。这就是为什么它更早工作的原因。 ;-) 感谢您指出了这一点。你能解释一下这是怎么发生的吗?
  • 你能检查一下python模块文档是否一切都正确,你应该尝试用pip再次安装。

标签: python windows beautifulsoup


【解决方案1】:

至少尝试安装python3.5+。 Python3.3 于 2013 年发布(7 年前!)。

您似乎在 Windows 上运行。在这种情况下,您可能只需下载 anaconda 即可让您的生活更轻松:https://anaconda.org/anaconda/beautifulsoup4

参考资料:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-22
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 2014-05-11
    • 1970-01-01
    • 2013-05-14
    • 2012-12-12
    相关资源
    最近更新 更多