centos6.4默认安装的python版本为2.6,但是beautifulsoup4 与python2.6兼容的不好,因此需要把python升级到python2.7才行。
下面介绍centos6.4中python升级为2.7的过程
python升级
首先需要安装的一些包
yum groupinstall "Development tools"
yum install zlib zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
安装python27:
官网http://www.python.org/download/下载Python 2.7.5 bzipped source tarball (for Linux, Unix or Mac OS X, more compressed)
下载Python-2.7.5.tar.bz2后,root权限解压,执行
[root@lydcentos Python-2.7.5]# ./configure --prefix=/usr/local
[root@lydcentos Python-2.7.5]# make && make altinstall
安装 Distribute
从https://pypi.python.org/pypi/distribute下载distribute-0.6.35.tar.gz,root权限解压,执行
[root@lydcentos distribute-0.6.35]# python2.7 setup.py install
This generates the script /usr/local/bin/easy_install-2.7 that you use to install packages for Python 2.7. It puts your packages in /usr/local/lib/python2.7/site-packages/
安装beautifulsoup:
官网http://www.crummy.com/software/BeautifulSoup/#Download下载beautifulsoup4-4.3.0.tar.gz,root权限解压,执行
[root@lydcentos beautifulsoup4-4.3.0]# python2.7 setup.py install
安装完后会提示Writing /usr/local/lib/python2.7/site-packages/beautifulsoup4-4.3.0-py2.7.egg-info