CentOS 7从Python 2.7升级至Python3.6.1

引言: 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、替换软链接

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的模式

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

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  查看是否成功

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.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   #建立软链接
 

 完毕!

posted @ 2018-03-06 15:47  茶记忆  阅读(339)  评论(0编辑  收藏  举报