升级python而不打破yum

tbe*_*ais 53 python centos yum

我最近通过源代码编译在CentOS机器上安装了Python 2.7.3.Python 2.7.3安装在/opt/python2.7上,当我安装它时,我刚刚更改了/ usr/bin/python以指向新版本.这显然是错误的,因为当我这样做时它打破了百胜.我会得到以下内容.

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.3 (default, May 15 2012, 17:45:42) 
[GCC 4.4.4 20100726 (Red Hat 4.4.4-13)]

If you cannot solve this problem yourself, please go to 
the yum faq at:
  http://yum.baseurl.org/wiki/Faq
Run Code Online (Sandbox Code Playgroud)

我将/ usr/bin/python更改为指向python 2.6.6,但现在2.6.6是python的默认版本.知道如何解决这个问题吗?

Dan*_*son 135

我已经编写了一个关于如何在CentOS 6和CentOS 7上安装最新版本的Python 2和Python 3 的快速指南.它目前涵盖了Python 2.7.13和Python 3.6.0.

您不应该更改Python的系统版本,因为它会破坏系统(正如您所发现的那样).只要保留原始系统版本,安装其他版本就可以正常工作.这可以通过/usr/local在运行configure时使用自定义前缀(例如)以及在安装Python构建时使用make altinstall(而不是正常make install)来实现.

只要您记得键入包括版本号的全名(例如"python2.7"或"pip2.7"),就可以使用多个版本的Python.如果您使用virtualenv完成所有Python工作,则会为您处理版本控制,因此请确保安装并使用virtualenv!


小智 14

vim `which yum`
modify #/usr/bin/python to #/usr/bin/python2.4
Run Code Online (Sandbox Code Playgroud)


lar*_*sks 5

/opt/python2.7/bin在...之前放入你的PATH环境变量/usr/bin或者只是习惯打字python2.7.