Centos7下不刪除python2.x的情況下安裝python3.x


Linux下默認系統自帶python2.X的版本,這個版本被系統很多程序所依賴,所以不建議刪除,如果使用最新的Python3那么我們知道編譯安裝源碼包和系統默認包之間是沒有任何影響的,所以可以安裝python3和python2共存

1、下載linux平台的python3.x的安裝包(我下載的是python3.6版本)

[root@localhost ~]# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

2、解壓python3.6安裝包

[root@localhost ~]# tar xf Python-3.6.1.tgz 
[root@localhost ~]# ll
total 22024
-rw-------.  1 root root     1238 Jun 25 10:54 anaconda-ks.cfg
drwxr-xr-x. 17  501  501     4096 Mar 21 03:47 Python-3.6.1
-rw-r--r--.  1 root root 22540566 Mar 21 03:47 Python-3.6.1.tgz

3、安裝python3.6,默認安裝路徑為/usr/local

  --prefix=PREFIX install architecture-independent files in PREFIX
  [/usr/local]

#安裝報錯,缺失依賴庫
[root@localhost Python-3.6.1]# ./configure 
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... no
checking for cc... no
checking for cl.exe... no
configure: error: in `/root/Python-3.6.1':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details
#安裝依賴庫
[root@localhost Python-3.6.1]# yum install gcc

#安裝python3.6
[root@localhost Python-3.6.1]# make && make install

#make && make install 報錯
zipimport.ZipImportError: can't decompress data; zlib not available
make: *** [install] Error 1
#安裝zlib-devel
[root@localhost Python-3.6.1]# yum install zlib-devel
#重新安裝
[root@localhost Python-3.6.1]# make && make install

 

4、python3.6已安裝成功,在/usr/local/bin下生成命令python3

[root@localhost local]# ll /usr/local/bin/
total 24656
lrwxrwxrwx. 1 root root        8 Jun 25 11:22 2to3 -> 2to3-3.6
-rwxr-xr-x. 1 root root      101 Jun 25 11:22 2to3-3.6
-rwxr-xr-x. 1 root root      242 Jun 25 11:22 easy_install-3.6
lrwxrwxrwx. 1 root root        7 Jun 25 11:22 idle3 -> idle3.6
-rwxr-xr-x. 1 root root       99 Jun 25 11:22 idle3.6
-rwxr-xr-x. 1 root root      214 Jun 25 11:22 pip3
-rwxr-xr-x. 1 root root      214 Jun 25 11:22 pip3.6
lrwxrwxrwx. 1 root root        8 Jun 25 11:22 pydoc3 -> pydoc3.6
-rwxr-xr-x. 1 root root       84 Jun 25 11:22 pydoc3.6 lrwxrwxrwx. 1 root root        9 Jun 25 11:22 python3 -> python3.6
-rwxr-xr-x. 2 root root 12604536 Jun 25 11:21 python3.6
lrwxrwxrwx. 1 root root       17 Jun 25 11:22 python3.6-config -> python3.6m-config
-rwxr-xr-x. 2 root root 12604536 Jun 25 11:21 python3.6m
-rwxr-xr-x. 1 root root     3097 Jun 25 11:22 python3.6m-config
lrwxrwxrwx. 1 root root       16 Jun 25 11:22 python3-config -> python3.6-config
lrwxrwxrwx. 1 root root       10 Jun 25 11:22 pyvenv -> pyvenv-3.6
-rwxr-xr-x. 1 root root      441 Jun 25 11:22 pyvenv-3.6

5、使用python3命令查看版本

[root@localhost local]# python3 -V
Python 3.6.1    
[root@localhost local]# python3
Python 3.6.1 (default, Jun 25 2017, 11:20:12) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.

 

參考:http://www.cnblogs.com/freeweb/p/5181764.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM