linux下将python2改为python3

我用的是centos7
Linux安装python3.6.4
环境准备:

yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel

安装python(默认下载到当前目录):

wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz

解压下好的文件

tar -zxvf Python-3.6.4.tgz

创建目录:

mkdir /usr/local/python3

准备安装python

yum install -y gcc 
cd Python-3.6.4
./configure --prefix=/usr/local/python3 --enable-optimizations
# 漫长的等待
make
make install

ln -s /usr/local/python3/bin/python3.6   /usr/bin/python
ln -s /usr/local/python3/bin/pip3   /usr/bin/pip3
cd /usr/bin
mv python python.bak
mv python3 python

在etc/profile最后一行中加入变量

export PATH="$PATH:/usr/local/python3/bin"

验证python --version
输入Python

>>>python 3.6

你可能感兴趣的:(python,Linux)