wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz --no-check-certificat
gunzip Python-3.6.1.tgz
tar xf Python-3.6.1.tgz
cd Python-3.6.1
mkdir /usr/local/python36
./configure --prefix=/usr/local/python36/
make && make install
然后出现报错:
zipimport.ZipImportError: can‘t decompress data; zlib not available
解决办法:
首先确认下是否安装了zlib、zlib-devel
[[email protected] Python-3.6.1]# pwd
/home/oracle/scripts/Python-3.6.1
然后cd Modules/
修改Setup
找到下面这句,去掉注释
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
然后重新执行下面:
./configure --prefix=/usr/local/python36/
make && make install
由于本身系统是2.x的版本:
[[email protected] Python-3.6.1]# mv /usr/bin/python /usr/bin/python_2.x
[[email protected] Python-3.6.1]# ln -sv /usr/local/python36/bin/python3 /usr/bin/python
python3 python3.6 python3.6-config python3.6m python3.6m-config python3-config
[[email protected] Python-3.6.1]# ln -sv /usr/local/python36/bin/python3.6 /usr/bin/python
`/usr/bin/python‘ -> `/usr/local/python36/bin/python3.6‘
[[email protected] Python-3.6.1]# python
Python 3.6.1 (default, Jul 13 2017, 14:31:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
python3.6版本安装完成后,原有的yum会无法使用,进行下面修改:
编辑/usr/bin/yum的第一行:
#!/usr/bin/python2.6 改成这样就可以使用了