1、安装python2.7.11
1.1、安装原则:
在不影响默认系统自带的python2.6.6的情况下安装python2.7.11
1.2、安装依赖包
shell>yum install -y gcc zlib-devel openssl openssl-devel python-devel readline-devel
1.3、下载python2.7.11
shell>cd /usr/srcshell>wget https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz
1.4、安装
将python2.7安装到/usr/local目录下
shell>tar zxvf Python-2.7.11.tgzshell>cd Python-2.7.11shell>./configure --prefix=/usr/local/python2.7shell>makeshell>make install
1.5、安装后目录结构
[root@localhost python2.7]# pwd/usr/local/python2.7[root@localhost python2.7]# lltotal 16drwxr-xr-x. 2 root root 4096 Feb 14 22:22 bindrwxr-xr-x. 3 root root 4096 Feb 14 22:22 includedrwxr-xr-x. 4 root root 4096 Feb 14 22:22 libdrwxr-xr-x. 3 root root 4096 Feb 14 22:22 share
2、安装setuptools
shell>cd /usr/srcshell>wget https://pypi.python.org/packages/source/s/setuptools/setuptools-20.1.1.tar.gzhttps://pypi.python.org/packages/ff/d4/209f4939c49e31f5524fa0027bf1c8ec3107abaf7c61fdaad704a648c281/setuptools-21.0.0.tar.gzshell>tar zxvf setuptools-20.1.1.tar.gz shell>cd setuptools-20.1.1shell>/usr/local/python2.7/bin/python2.7 setup.py install
3、安装pip
shell>cd /usr/srcshell>wget https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gzshell>tar zxvf pip-8.0.2.tar.gzshell>cd pip-8.0.2shell>/usr/local/python2.7/bin/python2.7 setup.py install
4、安装python包
shell>cd /usr/local/python2.7/binshell>./pip2.7 install yaml ua_parser user_agents
5、测试包安装是否成功
[root@localhost bin]# pwd/usr/local/python2.7/bin[root@localhost bin]# /usr/local/python2.7/bin/pythonPython 2.7.11 (default, Feb 14 2016, 22:19:05) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import yaml>>> import ua_parser>>> import user_agents>>>
6、创建软连接
将python2.7\pip2.7放到环境变量目录下。例如:/usr/bin/目录,这样在调用的饿时候就不用到python的安装目录下去执行,直接调用就可以。
shell>ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python2.7shell>ln -s /usr/local/python2.7/bin/pip2.7 /usr/bin/pip2.7