一. 安装python3并设为默认版本,与python2共存
1、下载Python3.4安装包
wget https://www.python.org/ftp/python/3.4.4/Python-3.4.4.tgz
2、解压、编译、安装
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
tar zxvf Python-3.4.4.tgz cd Python-3.4.4 ./configure --prefix=/usr/local/python3 make make install
3、创建Python3.4的链接,并且设置python3为默认版本(CentOS6.7默认安装的是Python2)
cd /usr/bin/
ln -s /usr/local/python3/bin/python3.4 python #如果不想为默认版本,把python改为python3
4. 因为执行yum需要python2版本,所以我们还要修改yum的配置
vi /usr/bin/yum 把#! /usr/bin/python修改为#! /usr/bin/python2
二. 安装模块
1. 安装beautifulsoup
wget https://
tar xvzf beautifulsoup4-4.5.1.tar.gz
cd beautifulsoup4-4.5.1
python setup.py install
2. 安装requests
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
pip install requests
3. 安装lxml,依赖有libxml2-devel,libxslt-devel
yum install libxml2-devel libxslt-devel -y
pip install lxml