Centos7下python2.x 和python3.x共存
生活随笔
收集整理的這篇文章主要介紹了
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.8s2018-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 shareroot@pts/1 $ /usr/local/python3/bin/python3 -V Python 3.6.1root@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. >>>轉載于:https://blog.51cto.com/colinspace/2059928
總結
以上是生活随笔為你收集整理的Centos7下python2.x 和python3.x共存的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: OpenCL-3-同步机制
- 下一篇: python微信跳一跳小游戏刷分