python學習筆記(7)--python版本升級


本節點標題
1、python升級
1.1、查看原版本
1.2、下載新版本的python
1.3、解壓縮 以及編譯
1.4、覆蓋原來的python鏈接
1.5、修復yum


=======================================================================================================================
1、python升級
linux操作系統大多自帶python。
下面以python2.4升級python2.7為例子講解操作。

1.1、查看原版本
[root@local_redhat ~]# python -V
Python 2.4.0

1.2、下載新版本的python
1 [root@local_redhat ~]# wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tgz

1.3、解壓縮 以及編譯
[root@local_redhat ~]# tar xvf Python-2.7.2.tar.bz2
[root@local_redhat Python-2.7.2]# ./configure --prefix=/usr/local/python27
[root@local_redhat Python-2.7.2]# make
[root@local_redhat Python-2.7.2]# make install
[root@local_redhat Python-2.7.2]# ls /usr/local/python27/ -al
total 28
drwxr-xr-x 6 root root 4096 Jul 14 00:21 .
drwxr-xr-x 20 root root 4096 Jul 14 00:17 ..
drwxr-xr-x 2 root root 4096 Jul 14 00:21 bin
drwxr-xr-x 3 root root 4096 Jul 14 00:21 include
drwxr-xr-x 4 root root 4096 Jul 14 00:21 lib
drwxr-xr-x 3 root root 4096 Jul 14 00:21 share

1.4、覆蓋原來的python鏈接
[root@local_redhat Python-2.7.2]# mv /usr/bin/python /usr/bin/python_old
[root@local_redhat Python-2.7.2]# ln -s /usr/local/python27/bin/python /usr/bin/
[root@local_redhat Python-2.7.2]# python
Python 2.7.2 (default, Jul 14 2016, 00:20:14)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

1.5、修復yum
此處已經可以正常使用python2.7了
但是因為yum是使用的2.4的版本來用的,現在輸入一下yum就會報錯
[root@local_redhat ~]# yum
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.2 (default, Jul 14 2016, 00:20:14)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)]

If you cannot solve this problem yourself, please go to
the yum faq at:
http://wiki.linux.duke.edu/YumFaq

所以還需要修改一下
[root@local_redhat Python-2.7.2]# vim /usr/bin/yum

#!/usr/bin/python #修改此處為2.4的位置(原來是二點幾就寫二點幾)
[root@local_redhat ~]# vim /usr/bin/yum

#!/usr/bin/python2.4
[root@local_redhat ~]# yum
Loaded plugins: fastestmirror
You need to give some command
usage: yum [options] COMMAND

List of Commands:

check-update Check for available package updates
clean Remove cached data
deplist List a package's dependencies
downgrade downgrade a package
erase Remove a package or packages from your system
groupinfo Display details about a package group
groupinstall Install the packages in a group on your system
grouplist List available package groups
groupremove Remove the packages in a group from your system
help Display a helpful usage message
info Display details about a package or group of packages
install Install a package or packages on your system
list List a package or groups of packages
localinstall Install a local RPM

此時yum 又可以使用了!
[root@local_redhat ~]# yum list


免責聲明!

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



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