Centos7下python2.x 和python3.x共存

摘要

目前centos7系統自帶的Python版本是2.7.5,這個版本唄系統中的很多程序鎖依賴,所有我們不可能去刪除它。如果這個時候我們還想用python3.x 版本,其實這裏有兩個方式,一個是利用pyenv 創建一個純淨的python3.x 環境,可以參考Centos 下 python 純淨虛擬環境;另外一個就是這裏介紹的。

下載

root@pts/0 $ wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
--2018-01-11 17:13:58--  https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz
正在解析主機 www.python.org (www.python.org)... 151.101.228.223, 2a04:4e42:36::223
正在連接 www.python.org (www.python.org)|151.101.228.223|:443... 已連接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:22540566 (21M) [application/octet-stream]
正在保存至: “Python-3.6.1.tgz”

100%[=========================================================================================>] 22,540,566  3.34MB/s 用時 7.8s

2018-01-11 17:14:06 (2.74 MB/s) - 已保存 “Python-3.6.1.tgz” [22540566/22540566])

依賴

正式安裝之前,需要先安裝一些依賴保證後續的安裝正常進行

yum install -y gcc gcc-c++ autoconf automake zlib-devel

安裝

# 解壓
root@pts/0 $ tar -zxf Python-3.6.1.tgz
root@pts/0 $ ll
總用量 26112
drwxr-xr-x 17  501  501     4096 3月  21 2017 Python-3.6.1
-rw-r--r--  1 root root 22540566 3月  21 2017 Python-3.6.1.tgz

# 編譯
默認會被安裝到 /usr/local下面。這裏我們通過configure  的--prefix參數自定義安裝路徑,方便以後的卸載

root@pts/0 $ cd Python-3.6.1
root@pts/0 $  ./configure --prefix=/usr/local/python3
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for python3.6... no
checking for python3... no
checking for python... python
checking for --enable-universalsdk... no
checking for --with-universal-archs... no
checking MACHDEP... linux
checking for --without-gcc... no
checking for --with-icc... no
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no

# 安裝
root@pts/1 $ make && make install

驗證

root@pts/1 $ ls -l /usr/local/python3/
總用量 16
drwxr-xr-x 2 root root 4096 1月  11 17:09 bin
drwxr-xr-x 3 root root 4096 1月  11 17:09 include
drwxr-xr-x 4 root root 4096 1月  11 17:09 lib
drwxr-xr-x 3 root root 4096 1月  11 17:09 share

root@pts/1 $ /usr/local/python3/bin/python3 -V
Python 3.6.1

root@pts/1 $ /usr/local/python3/bin/python3
Python 3.6.1 (default, Jan 11 2018, 17:08:20)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章