我在用自制在 Snow Leopard 上安装 python。
安装python(2.7.2)后,我/usr/local/share/python
在前面添加了PATH
。我还设置PYTHONPATH
为/usr/local/lib/python2.7/site-packages
。
如果我使用pip
安装xml文件或者反馈解析器例如,运行之后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.。)在 pip 中。
因此要安装特定版本,请运行:
sudo pip install beautifulsoup # version 3
或者
sudo pip install beautifulsoup4 # version 4