引言: CentOS是目前最为流行的Linux服务器系统,其默认的Python 2.x,但是根据python社区的规划,在不久之后,整个社区将向Python3迁移,且将不在支持Python2, 那该如何平滑迁移至Python3 呢?
下面直接来步骤,没太多杂语。
1、安装gcc
sudo yum -y install gcc sudo yum install openssl-devel -y
sudo yum install zlib-devel -y
sudo yum -y install kernel-devel
2、下载Python 3.x的安装包
sudo wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
3、解压
sudo tar xvf Python-3.6.1.tar.xz
4、编译并安装
sudo mkdir /usr/local/python3
cd Python-3.6.1
sudo ./configure --prefix=/usr/local/python3 --enable-optimizations
sudo make
sudo make install
5、替换软链接
cd /usr/bin
sudo mv python python.bak
sudo ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3 注意:此刻执行python3即进入python3.6的模式
6、解决yum
升级后yum不能正常使用的解决方法如下:
# sudo vi /usr/bin/yum
#!/usr/bin/python2.7 # sudo vi /usr/libexec/urlgrabber-ext-down
#!/usr/bin/python2.7
至此,以上基本安装完python3.
但是如果你想用pip3你得继续往下看。
7、首先安装setuptools
sudo wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26 sudo tar -zxvf setuptools-19.6.tar.gz cd setuptools-19.6
sudo python3 setup.py build sudo python3 setup.py install
ll |grep setuptools-19.6 查看是否成功
8、安装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..tar.gz cd pip-8.0. sudo python3 setup.py build sudo python3 setup.py install
sudo ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 #建立软链接
完毕!