【发布时间】: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