安装后仍然出现"ImportError: No module named BeautifulSoup"错误
我遇到了以下错误:
Traceback (most recent call last):
File "C:\Python27\files\samplefileoutput.py", line 1, in <module>
import BeautifulSoup
ImportError: No module named BeautifulSoup
当我尝试运行以下文件时:
import BeautifulSoup
f = open('c:\output.txt', 'a')
f.write('Hello World!\n')
f.close()
我以为我的安装是成功的。我在使用一台Windows 7的电脑。我解压了源代码包,然后在命令行中输入了“setup.py install”,在这之前我已经切换到了解压后的BeautifulSoup文件夹。安装过程中似乎没有出现错误信息。最后显示了这一行:
Writing C:\Python27\Lib\site-packages\beautifulsoup4-4.3.2-py2.7.egg-info
有没有人能给点建议?谢谢!
2 个回答
0
只需运行以下命令:
pip install BeautifulSoup
9
Beautiful Soup 4的模块叫做 bs4
。
from bs4 import BeautifulSoup
这样就可以用了,或者
import bs4
如果你想要导入整个模块的话。