首页 > 代码库 > BeautifulSoup的安装

BeautifulSoup的安装

在windows上安装步骤如下:
 
1. 对于python2.7,在官网上下载 BeautifulSoup4-4.1.0,(经试验,4-4.3.2不能安装成功)
2. 解压缩到本地硬盘,比如C:\Python27目录下
3. 运行cmd,输入命令:
      setup.py build
      setup.py install
4. 然后可以在 IDE中输入import BeautifulSoup 或者 from BeautifulSoup import BeautifulSoup ,没报错则安装成功
 
在mac上安装步骤如下:
 
1. 在官网上下载BeautifulSoup4-4.3.2,解压(解压到哪里都无所谓)
2. cd 进入刚解压的文件夹路径下,输入命令:
       python setup.py install
3. 然后可以看到,输入import bs4,在iTerm(python)和PyCharm、sublime text3都可以正常使用。但是在spyder上却报错,找不到bs4这个module模块。于是分别查看这四个界面中,python代码:
      import sys
      print sys.path
在iTerm中出现(pycharm和sublime text3类似):
>>> import sys>>> sys.path[‘‘, /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip, /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7, /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin, /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac, /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages, /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python, /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk, /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old, /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload, /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC, /Library/Python/2.7/site-packages]

然而spyder显示:

import syssys.pathOut[2]: [‘‘, /Applications/Spyder.app/Contents/Resources/lib/python2.7/spyderlib/utils/external, /Library/Python/2.7/site-packages, /Applications/Spyder.app/Contents/Resources, /Applications/Spyder.app/Contents/Resources/lib/python27.zip, /Applications/Spyder.app/Contents/Resources/lib/python2.7, /Applications/Spyder.app/Contents/Resources/lib/python2.7/plat-darwin, /Applications/Spyder.app/Contents/Resources/lib/python2.7/plat-mac, /Applications/Spyder.app/Contents/Resources/lib/python2.7/plat-mac/lib-scriptpackages, /Applications/Spyder.app/Contents/Resources/lib/python2.7/lib-tk, /Applications/Spyder.app/Contents/Resources/lib/python2.7/lib-old, /Applications/Spyder.app/Contents/Resources/lib/python2.7/lib-dynload, /Applications/Spyder.app/Contents/Resources/lib/python2.7/site-packages.zip, /Applications/Spyder.app/Contents/Resources/lib/python2.7/site-packages, /Applications/Spyder.app/Contents/Resources/lib/python2.7/IPython/extensions, /Users/jyy/.ipython]

安装的package放在/Library/Python/2.7/site-packages目录下,进入可以看到bs4的文件夹(主要是.pyc和.py文件)。然而spyder默认的路径则不在这目录下,解决办法是在spyder的PYTHONPATH manager 中加入该路径即可。

 

BeautifulSoup的安装