下载Python-3.6.5
[root@Master /]# cd /home
[root@Master home]# wget http://cdn.npm.taobao.org/dist/python/3.6.5/Python-3.6.5.tgz
解压Python-3.6.5.tgz
[root@Master home]# tar -zxvf Python-3.6.5.tgz
安装gcc和zlib等
[root@Master home]# yum install -y gcc
[root@Master home]# yum install -y zlib*
[root@Master Python-3.6.5]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel #确保pip的时候不会有出错
配置安装路径为/usr/local/python3
[root@Master home]# cd Python-3.6.5/
[root@Master Python-3.6.5]# ./configure --prefix=/usr/local/python3 --with-ssl
编译
[root@Master Python-3.6.5]# make
可能会遇到如下问题:
gcc: internal compiler error: Killed (program cc1)
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
make: *** [Objects/unicodeobject.o] Error 4
修改Makefile文件,把‘-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes’中的‘O3’改为‘O2’
[root@Master Python-3.6.5]# vim Makefile
重新make后正常
安装
[root@Master Python-3.6.5]# make install
建立软链接
[root@Master Python-3.6.5]# ln -s /usr/local/python3/bin/python3 /usr/bin/python3
[root@Master Python-3.6.5]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
测试
[root@Master Python-3.6.5]# python3
Python 3.6.5 (default, Apr 22 2018, 17:24:20)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print('hello world')
hello world
>>>