1、下载安装包

wget http://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

2、解压

tar -xzvf Python-3.6.1.tgz

3、进入解压之后的文件夹

cd Python-3.6.1

4、在编译之前现在/use/local下建python3的文件夹作为python3安装路径

mkdir /usr/local/python3

5、开始编译安装

./configure --prefix=/usr/local/python3

6、此时老版本python版本未删除,可以修改老版本的链接

mv /usr/bin/python /usr/bin/python2

7、建立新python的版本链接

ln -s /usr/local/python3/bin/python3 /usr/bin/python

8、这个时候python3就安装完成了,可以下面查看当前python版本

python -V    #输出 Python 3.6.1

9、此时服务器之前的python2.7也是通过 python2 正常使用的


如果安装出现以下错误

[root@master ~]#./configure --prefix=/usr/local/python3.6 
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for --enable-universalsdk... no
checking for --with-universal-archs... 32-bit
checking MACHDEP... linux
checking for --without-gcc... no
checking for gcc... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/usr/local/src/pythonSoft/Python-3.3.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details

是因为本机缺少gcc编译环境,可直接通过yum安装gcc编译环境

yum install -y gcc

end~

标签: linux, python, centos

添加新评论