CentOS6.x機器安裝Python2.7.x

 

準備環境:CentOS6.9機器html

 

1.查看機器默認的Python版本python

[root@hlmcent69nma ~]# python -V
Python 2.6.6
[root@hlmcent69nma ~]# whereis python
python: /usr/bin/python /usr/bin/python2.6 /usr/lib/python2.6 /usr/lib64/python2.6 /usr/local/bin/python /usr/include/python2.6 /usr/share/man/man1/python.1.gz

 

2.安裝gccvim

[root@hlmcent69nma ~]# yum install gcc -y

 

3.下載最新的Python2.7.x安裝包,解壓並進入指定目錄ide

[root@hlmcent69nma ~]# wget https://www.python.org/ftp/python/2.7.14/Python-2.7.14.tgz
[root@hlmcent69nma ~]# ll Python-2.7.14.tgz 
-rw-r--r--. 1 root root 17176758 Sep 17 02:05 Python-2.7.14.tgz
[root@hlmcent69nma ~]# tar zxvf Python-2.7.14.tgz
[root@hlmcent69nma ~]# cd Python-2.7.14
[root@hlmcent69nma Python-2.7.14]# ll
total 1000
-rw-r--r--.  1 1000 1000  10914 Sep 17 01:38 aclocal.m4
-rwxr-xr-x.  1 1000 1000  44259 Sep 17 01:38 config.guess
-rwxr-xr-x.  1 1000 1000  36515 Sep 17 01:38 config.sub
-rwxr-xr-x.  1 1000 1000 442959 Sep 17 01:38 configure
-rw-r--r--.  1 1000 1000 141572 Sep 17 01:38 configure.ac
drwxr-xr-x. 22 1000 1000   4096 Sep 17 01:38 Demo
drwxr-xr-x. 18 1000 1000   4096 Sep 17 01:55 Doc
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 Grammar
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 Include
-rwxr-xr-x.  1 1000 1000   7122 Sep 17 01:38 install-sh
drwxr-xr-x. 47 1000 1000  12288 Sep 17 01:38 Lib
-rw-r--r--.  1 1000 1000  12757 Sep 17 01:38 LICENSE
drwxr-xr-x. 11 1000 1000   4096 Sep 17 01:38 Mac
-rw-r--r--.  1 1000 1000  48553 Sep 17 01:38 Makefile.pre.in
drwxr-xr-x.  5 1000 1000   4096 Sep 17 01:38 Misc
drwxr-xr-x.  9 1000 1000   4096 Sep 17 01:38 Modules
drwxr-xr-x.  3 1000 1000   4096 Sep 17 01:38 Objects
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 Parser
drwxr-xr-x.  9 1000 1000   4096 Sep 17 01:38 PC
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 PCbuild
-rw-r--r--.  1 1000 1000  35170 Sep 17 01:38 pyconfig.h.in
drwxr-xr-x.  2 1000 1000   4096 Sep 17 01:38 Python
-rw-r--r--.  1 1000 1000  55670 Sep 17 01:38 README
drwxr-xr-x.  5 1000 1000   4096 Sep 17 01:38 RISCOS
-rw-r--r--.  1 1000 1000  99231 Sep 17 01:38 setup.py
drwxr-xr-x. 23 1000 1000   4096 Sep 17 01:38 Tools

 

4.配置,編譯,編譯安裝ui

[root@hlmcent69nma Python-2.7.14]# ./configure --prefix=/usr/local/python/python2.7
[root@hlmcent69nma Python-2.7.14]# make
[root@hlmcent69nma Python-2.7.14]# make install

備註:
執行 ./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。this

 

5.查看系統的Python版本,仍是2.6.xurl

[root@hlmcent69nma ~]# python -V
Python 2.6.6

 

6.查看新安裝的Python版本,當前系統的Python版本,並將系統指向的Python從2.6.x修改成2.7.x,再次查看當前系統的Python版本,已經變動爲2.7.xspa

[root@hlmcent69nma ~]# /usr/local/python/python2.7/bin/python2.7 -V
Python 2.7.14
[root@hlmcent69nma ~]# /usr/bin/python -V
Python 2.6.6
[root@hlmcent69nma ~]# mv /usr/bin/python /usr/bin/python.bak
[root@hlmcent69nma ~]# ln -s /usr/local/python/python2.7/bin/python2.7 /usr/bin/python
[root@hlmcent69nma ~]# python -V
Python 2.7.14

 

7.可是發現yum命令沒法使用了,因爲yum是基於python2.6才能正常工做,需單獨將yum指向python2.6版本操作系統

[root@hlmcent69nma ~]# yum list
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.14 (default, Nov 30 2017, 11:54:55) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]
If you cannot solve this problem yourself, please go to 
the yum faq at:
http://yum.baseurl.org/wiki/Faq

[root@hlmcent69nma ~]# vim /usr/bin/yumcode

 

參考連接:

https://www.cnblogs.com/perallina/p/5253329.html

https://www.cnblogs.com/lclq/archive/2016/06/27/5620196.html

相關文章
相關標籤/搜索