引言: CentOS是目前最爲流行的Linux服務器系統,其默認的Python 2.x,可是根據python社區的規劃,在不久以後,整個社區將向Python3遷移,且將不在支持Python2, 那該如何平滑遷移至Python3 呢?python
下面直接來步驟,沒太多雜語。linux
一、安裝gcc服務器
sudo yum -y install gcc
sudo yum install openssl-devel -y
sudo yum install zlib-devel -y
sudo yum -y install kernel-devel
二、下載Python 3.x的安裝包python2.7
sudo wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
三、解壓ui
sudo tar xvf Python-3.6.1.tar.xz
四、編譯並安裝url
sudo mkdir /usr/local/python3 cd Python-3.6.1 sudo ./configure --prefix=/usr/local/python3 --enable-optimizations sudo make
sudo make install
五、替換軟連接spa
1 cd /usr/bin 2 sudo mv python python.bak 3 sudo ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
注意:此刻執行python3即進入python3.6的模式
六、解決yumcode
升級後yum不能正常使用的解決方法以下:blog
# sudo vi /usr/bin/yum #!/usr/bin/python2.7 # sudo vi /usr/libexec/urlgrabber-ext-down #!/usr/bin/python2.7
至此,以上基本安裝完python3.ip
可是若是你想用pip3你得繼續往下看。
七、首先安裝setuptools
1 sudo wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26 2 3 sudo tar -zxvf setuptools-19.6.tar.gz 4 5 cd setuptools-19.6 7 sudo python3 setup.py build 8 9 sudo python3 setup.py install
ll |grep setuptools-19.6 查看是否成功
八、安裝pip
sudo wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb sudo tar -zxvf pip-8.0.2.tar.gz cd pip-8.0.2 sudo python3 setup.py build sudo python3 setup.py install
sudo ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 #創建軟連接
完畢!