1. 程式人生 > >python--linux安裝

python--linux安裝

too python3 lai conda tool 驗證 ks.cfg cfg usr

centos7

查看默認Python版本自帶2.7.5版本

[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[[email protected]-node1 ~]# python -V
Python 2.7.5

升級版本-3.x

1、安裝gcc,用於編譯Python源碼

[[email protected] ~]# yum install gcc

2、下載源碼包

官網下載:https://www.python.org

/ftp/python/

3、解壓並進入源碼文件

[[email protected] ~]# ll
total 14468
-rw-------. 1 root root     1208 Dec 15  2016 anaconda-ks.cfg
-rw-r--r--  1 root root 14808460 Apr 20 15:47 Python-3.5.0.tar.xz
[[email protected]-node1 ~]# tar xf Python-3.5.0.tar.xz
[[email protected]-node1 ~]# cd Python-3.5
.0/ [[email protected]-node1 Python-3.5.0]# ll total 980 -rw-r--r-- 1 1000 1000 8466 Sep 13 2015 aclocal.m4 -rwxr-xr-x 1 1000 1000 42856 Sep 13 2015 config.guess -rwxr-xr-x 1 1000 1000 35740 Sep 13 2015 config.sub -rwxr-xr-x 1 1000 1000 464952 Sep 13 2015 configure -rw-r--r-- 1 1000 1000 150676 Sep 13 2015 configure.ac drwxrwxr
-x 18 1000 1000 4096 Sep 13 2015 Doc drwxrwxr-x 2 1000 1000 20 Sep 13 2015 Grammar drwxrwxr-x 2 1000 1000 4096 Sep 13 2015 Include -rwxr-xr-x 1 1000 1000 7122 Sep 13 2015 install-sh drwxrwxr-x 46 1000 1000 8192 Sep 13 2015 Lib -rw-r--r-- 1 1000 1000 12761 Sep 13 2015 LICENSE drwxrwxr-x 8 1000 1000 151 Sep 13 2015 Mac -rw-r--r-- 1 1000 1000 56690 Sep 13 2015 Makefile.pre.in drwxrwxr-x 2 1000 1000 4096 Sep 13 2015 Misc drwxrwxr-x 11 1000 1000 4096 Sep 13 2015 Modules drwxrwxr-x 4 1000 1000 4096 Sep 13 2015 Objects drwxrwxr-x 2 1000 1000 4096 Sep 13 2015 Parser drwxrwxr-x 6 1000 1000 4096 Sep 13 2015 PC drwxrwxr-x 2 1000 1000 4096 Sep 13 2015 PCbuild drwxrwxr-x 2 1000 1000 79 Sep 13 2015 Programs -rw-r--r-- 1 1000 1000 41790 Sep 13 2015 pyconfig.h.in drwxrwxr-x 3 1000 1000 4096 Sep 13 2015 Python -rw-r--r-- 1 1000 1000 6740 Sep 13 2015 README -rw-r--r-- 1 1000 1000 98075 Sep 13 2015 setup.py drwxrwxr-x 22 1000 1000 4096 Sep 13 2015 Tools

4、編譯安裝

[[email protected] Python-3.5.0]# ./configure
[[email protected]-node1 Python-3.5.0]# make all
[[email protected]-node1 Python-3.5.0]# make install

註:編譯需要等一段時間~

5、查看版本

[[email protected] Python-3.5.0]# /usr/local/bin/python3.5 -V
Python 3.5.0

6、修改默認Python版本

[[email protected] Python-3.5.0]# mv /usr/bin/python /usr/bin/python2.7.5         #移走舊版本的python並命名為2.7.5
[[email protected]-node1 Python-3.5.0]# ln -s /usr/local/bin/python3.5 /usr/bin/python  #做軟連接
[[email protected]-node1 Python-3.5.0]# python -V                                       #驗證默認版本
 Python 3.5.0

7、防止yum執行異常,修改yum使用的Python版本

[[email protected] Python-3.5.0]# vim /usr/bin/yum    #將頭部 #!/usr/bin/python 修改為 #!/usr/bin/python3.5
[[email protected]-node1 Python-3.5.0]# cat /usr/bin/yum
#!/usr/bin/python3.5
import sys

python--linux安裝