我使用以下命令安装了BeautifulSoup:
sudo easy_install BeautifulSoup4
我收到了消息:
Searching for BeautifulSoup4
Best match: beautifulsoup4 4.1.3
Processing beautifulsoup4-4.1.3-py2.6.egg
beautifulsoup4 4.1.3 is already the active version in easy-install.pth
Using /Library/Python/2.6/site-packages/beautifulsoup4-4.1.3-py2.6.egg
Processing dependencies for BeautifulSoup4
Finished processing dependencies for BeautifulSoup4
我正在尝试导入BeautifulSoup lib。
>>> from BeautifulSoup import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named BeautifulSoup
或:
>>> from bs4 import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bs4
我的Python版本是:
python --version
Python 2.7.3
修改
我理解:
Using /Library/Python/2.6/site-packages/beautifulsoup4-4.1.3-py2.6.egg
可能意味着Python版本之间存在冲突
如何注册此模块?感谢
答案 0 :(得分:3)
应该是,
from bs4 import BeautifulSoup
答案 1 :(得分:0)
这样做:
easy_install pip
pip install beautifulsoup4
。这应该有效。确保将其作为带有pip list
的模块,如果您将美丽的汤作为输出,那么是的,您可以使用它。
答案 2 :(得分:0)
经过一番研究后,我发现这解决了这个问题:
pip uninstall BeautifulSoup4
将卸载位于以下位置的软件包:
/Library/Python/2.6/site-packages/
和
easy_install-2.7 BeautifulSoup4
将成功安装该软件包:
/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
我已经使用其他一些具有相同问题的软件包检查了这个过程,但它确实有效。