1. 程式人生 > >Centos6.5安裝python2.7與pip

Centos6.5安裝python2.7與pip

fig inux conf 編譯安裝 ins collect pen 軟連接 zip2

安裝Python2.7

安裝環境

[root@localhost1 ~]# cat /etc/redhat-release 
CentOS release 6.5 (Final)
[root@localhost1 ~]# uname -a
Linux localhost1 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

安裝依賴包

[root@localhost1 ~]# yum -y install gcc openssl-devel bzip2-devel

下載python源碼包

[root@localhost1 ~]# cd /usr/src/
[root@localhost1 src]# wget https://www.python.org/ftp/python/2.7.15/Python-2.7.15.tgz

解壓

[root@localhost1 src]# tar xf Python-2.7.15.tgz 
[root@localhost1 src]# cd Python-2.7.15
[root@localhost1 Python-2.7.15]#

  

編譯安裝

[root@localhost1 Python-2.7.15]# ./configure --enable-optimizations
[root@localhost1 Python-2.7.15]# make
[root@localhost1 Python-2.7.15]# make altinstall

  

查看安裝

[root@localhost1 Python-2.7.15]# /usr/local/bin/python2.7 -V
Python 2.7.15

  

設置軟連接

[root@localhost1 Python-2.7.15]# mv /usr/bin/python{,-old}
[root@localhost1 Python-2.7.15]# ln -s /usr/local/bin/python2.7 /usr/bin/python

  

配置yum

[root@localhost1 Python-2.7.15]# sed -i ‘s/python/python-old/‘ /usr/bin/yum

  

安裝pip

[root@localhost1 Python-2.7.15]# python -m ensurepip
Collecting setuptools
Collecting pip
Installing collected packages: setuptools, pip
Successfully installed pip-9.0.3 setuptools-39.0.1
[root@localhost1 Python-2.7.15]# pip -V
pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)

Centos6.5安裝python2.7與pip