系统:CentOS Linux release 7.3.1611 (Core) (不是mini)
1.安装依赖
yum install -y gcc zlib-devel openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel ncurses-devel xz-devel tk-devel
2.下载
wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2rc1.tar.xz xz -d Python-3.6.2rc1.tar.xz tar -xvf Python-3.6.2rc1.tar
3.进入源代码包并编译安装
cd Python-3.6.2rc1/ ./configure --prefix=/usr/local/python3 --enable-optimizations
参数,–prefix 是安装目录,–enable-optimizations 是启用优化选项(LTO,PGO 等),会增加编译时间
make make install
Warning:make install can overwrite or masquerade the python3 binary. make altinstall is therefore recommended instead of make install since it only installs exec_prefix/bin/pythonversion.
4.查看版本
/usr/local/python3/bin/python3 --version
Python 3.6.2rc1
5.环境配置
ln -s /usr/local/python3/bin/python3 /usr/bin/python3[root@CentOS7 ~]# python3
Python 3.6.2rc1 (default, Jul 6 2017, 12:02:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>
系统里还有2.7.5版本,可创建虚拟环境
(以下步骤可忽略,参考文档:https://docs.python.org/3/library/venv.html)
python3 -m venv py3
激活虚拟环境
source py3/bin/activate
查看版本
python -V
Python 3.6.2rc1
——-操作过程——
[root@CentOS7 ~]# python3 -m venv py3 [root@CentOS7 ~]# source py3/bin/activate (py3) [root@CentOS7 ~]# python -V Python 3.6.2rc1