[英]Error importing BeautifulSoup - Conflict with Python version
我使用以下命令安裝了 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 庫。
>>> 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 的版本之間存在沖突
我怎樣才能注冊這個模塊? 謝謝
它應該是,
from bs4 import BeautifulSoup
做這個:
easy_install pip
pip install beautifulsoup4
。 那應該行得通。 確保你將它作為一個帶有pip list
的模塊,如果你看到 Beautiful Soup 作為輸出,那么是的,你讓它工作了。
經過一番研究,我發現這解決了這個問題:
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/
我還檢查了其他一些具有相同問題的軟件包的過程並且它有效。
你還必須
pip install bs4
並使用
>>> from bs4 import BeautifulSoup
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.