Centos 6自帶的python版本是 2.6 , 但是很多時候一些開發和使用需要2.7版本。接下來,我們升級Python版本從2.6-2.7或者你可以從2.6-3以上,步驟都是類似的。
1、更新開發工具集
yum -y update
yum groupinstall -y 'development tools'
yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget
2、下載和解壓你要更新至Python目的版本號
wget http://mirrors.sohu.com/python/2.7.13/Python-2.7.13.tar.xz
xz -d Python-2.7.13.tar.xz
tar -xvf Python-2.7.13.tar
此過程,解壓的文件非常之多。我更新至2.7.13,你隨意。
3、編譯
cd Python-2.7.13
./configure --prefix=/usr/local
make && make install?
此過程,你可能會遇到跟我一樣的錯誤,不過我覺得可能性很小。是什么樣的呢?請看,不過這個錯誤很容易解決,關鍵之處我加粗了。
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux2
checking EXTRAPLATDIR...
checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... /home/soft/bin/gcc
checking whether the C compiler works... no
configure: error: in `/root/Python-2.7.13':
configure: error: C compiler cannot create executables
See `config.log' for more details
gcc已經安裝,看一下目錄就能知道錯誤原因和解決方法。
[root@cdh Python-2.7.13]#which gcc
/usr/bin/gcc
我做了軟連接ln -s /usr/bin/gcc /home/soft/bin/gcc到/home/soft/bin/gcc
然后進行編譯就通過了。
If you want a release build with all optimizations active (LTO, PGO, etc),
please run ./configure --enable-optimizations
4、驗證
python -V
which python
Python 2.7.13
至此,Python主體升級完畢,一些工具包可以意并安裝,方便日后使用。
5、安裝 setuptools
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz
tar -xvf setuptools-1.4.2.tar.gz
python2.7 setup.py install
6、安裝 PIP
這是重要的,Python的一些庫都需要使用pip安裝,用起來十分方便。
curl? https://bootstrap.pypa.io/get-pip.py | python2.7 -
比如安裝flask,pymongo,virtualenv等可以通過pip安裝。
pip install Flask
pip install pymongo
pip install virtualenv
完結。