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
[root@oracle 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
注意:
這是沒有make && make install之前
或者直接yum install -y zlib、zlib-devel,然後修改Modules/Setup.dist中:
找到下面這句,去掉註釋
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz
由於本身系統是2.x的版本:
[root@oracle Python-3.6.1]# mv /usr/bin/python /usr/bin/python_2.x
[root@oracle 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
[root@oracle Python-3.6.1]# ln -sv /usr/local/python36/bin/python3.6 /usr/bin/python
`/usr/bin/python' -> `/usr/local/python36/bin/python3.6'
[root@oracle 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 改成這樣就可以使用了
解決:ImportError: No module named '_sqlite3'
yum install sqlite-devel
tar xf Python-3.6.1.tgz
然後重新編譯python3.6
cd Python-3.6.1
./configure --prefix=/usr/local/python36/
make && make install
For multiple versions of Python, use altinstall
instead of install
.
由於該linux上存在多版本的python,所以改為:
make && make altinstall
[root@node1 Python-3.6.1]# python
Python 3.6.1 (default, Aug 16 2017, 16:05:59)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> import sqlite3
>>> exit()