我在用自製在 Snow Leopard 上安裝 python。
安裝 python (2.7.2) 後,我將/usr/local/share/python
其添加到PATH
.我也設定PYTHONPATH
為/usr/local/lib/python2.7/site-packages
.
如果我使用pip
安裝lxml或者feed解析器,例如,運行後python
,我可以import lxml
毫無問題。
運行後pip install BeautifulSoup
,上面列出的目錄中存在一個.egg-info
BeautifulSoup 的目錄site-packages
,以及該bs4
目錄,但from BeautifulSoup import BeautifulSoup
只是在 python 解釋器中給我一個錯誤。
sys.path
是:
['',
'/usr/local/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg',
'/Users/Chris/src/python-pinboard',
'/usr/local/lib/python2.7/site-packages',
'/usr/local/Cellar/python/2.7.2/lib/python27.zip',
'/usr/local/Cellar/python/2.7.2/lib/python2.7',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/plat-darwin',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/plat-mac',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/plat-mac/lib-scriptpackages',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/lib-tk',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/lib-old',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/lib-dynload',
'/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages']
知道發生了什麼事嗎?
更新:找到解決方案
預設情況下,安裝最新的 BeautifulSoup 4.0b。使用穩定發布pip install BeautifulSoup==3.2.0
、導入等工作。
答案1
預設情況下,安裝最新的 BeautifulSoup 4.0b。使用穩定發布pip install BeautifulSoup==3.2.0
、導入等工作。
答案2
BeautifulSoup 現在分為beautifulsoup
(版本 3.。)和beautifulsoup4
(版本 4.。)以點為單位。
因此,要安裝特定版本,請執行:
sudo pip install beautifulsoup # version 3
或者
sudo pip install beautifulsoup4 # version 4