Centos 7, 當前的Python版本2.7.12python
>> cat /etc/os-releaselinux
命令能夠查看系統的版本信息:sql
cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"vim
REDHAT_SUPPORT_PRODUCT="centos"centos
>>cd /usr/local/src //放在src目錄下優化
>>wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xzui
>> yum install openssl-devel bzip2-devel expat-devel gdbm-develreadline-devel sqlite-develurl
在/usr/local/src/目錄下,先解壓xz文件,再解壓tar文件。spa
>> xz -d Python-3.6.2.tar.xzdebug
>> tar xvf Python-3.6.2.tar
>>cd .. // 切換到/usr/local/
>>mkdir Python3
>>cd /usr/local/Python3 //用來存放編譯後的python3
>>cd /usr/local/src/Python-3.6.2
>> ./configure --prefix=/usr/local --enable-optimizations
其中:--enable-optimizations是python的優化命令,能夠提高10%到20%的效率,但安裝過程會變慢
>> make
>> make install
>> cd /usr/bin
>> mv python python.backup \\備份python,在linux系統中後綴沒有意義,因此python.backup只是換了個名字
>> ln -s /usr/local/Python3/bin/python3.6 /usr/bin/python \\這裏是python3.6,不是python3.6.2\\-s建立軟連接
由於yum依賴python2,python3中沒有yum
>> cd /usr/bin
>> ls yum*
yum yum-config-manager yum-debug-restore yum-groups-manager
yum-builddep yum-debug-dump yumdownloader
使用vim更改以上文件
#如: vim yum
以上7個文件所有
將# !/usr/bin/python 改成 # !/usr/bin/python2
更改完畢後,依次按ESC Ctrl+: wq Enter
# vim /usr/bin/gnome-tweak-tool
# !/usr/bin/python 改成 # !/usr/bin/python2
# vim /usr/libexec/urlgrabber-ext-down
# !/usr/bin/python 改成 # !/usr/bin/python2