centos 7 安裝python3.5.1

來源:互聯網
上載者:User

標籤:wget   新版本   test   3.5   程式   配置   UI   sha   uname   

系統:

[[email protected] ~]# cat /etc/centos-release

CentOS Linux release 7.2.1511 (Core)

核心:

[[email protected] ~]# uname -r
3.10.0-327.el7.x86_64

1.查看是否已經安裝Python

Centos7預設安裝了python2.7.5 因為一些命令要用它比如yum 它使用的是python2.7.5。

使用python -V命令查看一下是否安裝Python:

[[email protected] ~]# python -V
Python 2.7.5

查看Python可執行檔的位置:

[[email protected] ~]# which python
/usr/bin/python

進入到bin目錄:

[[email protected] ~]# cd /usr/bin/

[[email protected] bin]# ll python*
lrwxrwxrwx. 1 root root 7 3月 29 04:05 python -> python2
lrwxrwxrwx. 1 root root 9 3月 29 04:05 python2 -> python2.7
-rwxr-xr-x. 1 root root 7136 11月 20 2015 python2.7

可以看到可執行檔python指向python2,python2又指向python2.7也就是說Python命令執行的系統預裝的Python2.7。

要安裝Python的其他版本先執行mv python python.bak命令備份python檔案。

[[email protected] bin]# mv python python.bak

安裝新版本的python(3.5.1)

[[email protected] ~]# wget https://www.python.org/ftp/python/3.5.1/Python-3.5.1.tgz

[[email protected] ~]# tar -zxvf Python-3.5.1.tgz     

[[email protected] ~]# cd Python-3.5.1         

[[email protected] Python-3.5.1]# ./configure --prefix=/usr/local/python/python3    #--prefix指定安裝目錄,不指定安裝目錄也可以(單./configure也可以)

    執行 ./configure --prefix=/usr/local/python/python3 命令。./configure命令執行完畢之後建立一個檔案creating Makefile,供下面的make命令使用 執行make install之後就會把程式安裝到我們指定的目錄中去。

    Configure是一個可執行指令碼,它有很多選項,在待安裝的源碼路徑下使用命令./configure –help輸出詳細的選項列表。

    其中--prefix選項是配置安裝的路徑,如果不配置該選項,安裝後可執行檔預設放在/usr /local/bin,庫檔案預設放
    在/usr/local/lib,設定檔預設放在/usr/local/etc,其它的資源檔放在/usr /local/share,比較淩亂。

    如果配置--prefix,如:
    ./configure --prefix=/usr/local/test
    可以把所有資源檔放在/usr/local/test的路徑中,不會雜亂。
    用了—prefix選項的另一個好處是卸載軟體或移植軟體。當某個安裝的軟體不再需要時,只須簡單的刪除該安裝目錄,
    就可以把軟體卸載得乾乾淨淨;移植軟體只需拷貝整個目錄到另外一個機器即可(相同的作業系統)。

    當然要卸載程式,也可以在原來的make目錄下用一次make uninstall,但前提是make檔案指定過uninstall。

    然後執行make、make install命令。

    安裝成功之後進入到python3檔案夾可以看到Python的可執行檔目錄、lib目錄等相關目錄。

[[email protected] Python-3.5.1]# make

[[email protected] Python-3.5.1]# make install

[[email protected] Python-3.5.1]# cd /usr/local/python/python3/
[[email protected] python3]# ls
bin include lib share
[[email protected] python3]#ln -s /usr/local/python/python3/bin/python3 /usr/bin/python    #建立軟串連

[[email protected] python3]# python -V      #查看新安裝的python是否安裝成功
Python 3.5.1

安裝成功:

退出python的命令是:quit() 

修改yum設定檔:

因為yum使用python2,因此替換為python3後可能無法正常工作,繼續使用這個python2.7.5

因此修改yum設定檔。

 

把檔案頭部的#!/usr/bin/python改成#!/usr/bin/python2.7  儲存退出即可。

因為yum使用python2,因此替換為python3後可能無法正常工作,繼續使用這個python2.7.5因此修改yum設定檔(vi /usr/bin/yum)。把檔案頭部的#!/usr/bin/python改成#!/usr/bin/python2.7儲存退出即可

 

centos 7 安裝python3.5.1

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.