Linux 将默认 Python 版本从 2.4 更改为 2.6

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3339530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-03 20:18:14  来源:igfitidea点击:

Change default Python version from 2.4 to 2.6

pythonlinuxversion

提问by Kristopher Ives

I'm wanting to use some newer software that requires Python 2.6, and we currently have both 2.4and 2.6installed on our dedicated CentOS server, which looks like this:

我想使用一些需要 Python 的较新软件,2.6我们目前在专用 CentOS 服务器上安装2.42.6安装了这两个软件,如下所示:

$ which python
/usr/local/bin/python
$ which python2.6
/usr/bin/python2.6
$ which python2.4
/usr/local/bin/python2.4
$ ls -l /usr/local/bin/py*
-rwxr-xr-x 1 root root      81 Aug  9  2007 /usr/local/bin/pydoc
-rwxr-xr-x 2 root root 3394082 Aug  9  2007 /usr/local/bin/python
-rwxr-xr-x 2 root root 3394082 Aug  9  2007 /usr/local/bin/python2.4

How can I switch it to start using 2.6as the default python?

如何将其切换为开始使用2.6作为默认值python

采纳答案by unutbu

As root:

作为根:

ln -sf /usr/bin/python2.6 /usr/local/bin/python

This will make a symbolic link from /usr/local/bin/python --> /usr/bin/python2.6 (replacing the old hardlink).

这将创建一个来自 /usr/local/bin/python --> /usr/bin/python2.6 的符号链接(替换旧的硬链接)。

回答by C Walker

rm /usr/local/bin/python
ln -s /usr/local/bin/python2.6 /usr/local/bin/python

rm /usr/local/bin/python
ln -s /usr/local/bin/python2.6 /usr/local/bin/python

回答by Jian

As an alternative, you can also just add an alias for the command "python" in the your bash shell's startup file.

作为替代方案,您也可以在 bash shell 的启动文件中为命令“python”添加一个别名。

so open the startup file: emacs ~/.bashrc

所以打开启动文件:emacs ~/.bashrc

in the editor u append: alias "python" "python2.6"

在编辑器中添加:别名“python”“python2.6”

and restart the shell.

并重新启动外壳。

回答by gezgingun

I had similar problem when using meld, I simply renamed the one under local and it worked. Not a good solution I know, but I can always take it back.

我在使用 meld 时遇到了类似的问题,我只是在 local 下重命名了一个并且它起作用了。我知道这不是一个好的解决方案,但我总是可以收回它。

sudo mv /usr/local/bin/python /usr/local/bin/re_python

回答by Linux user

Add an aliasfor the command "python" in the your bash shell's startup file. DON'Tchange a symbolic link from /usr/bin/python, because changing the default Python (in Ubuntu or Linux Mint for example) may break your system

在 bash shell 的启动文件中为命令“python”添加别名不要更改 /usr/bin/python 中的符号链接,因为更改默认 Python(例如在 Ubuntu 或 Linux Mint 中)可能会破坏您的系统

P.S.: read other answers

PS:阅读其他答案

回答by Slipstream

In CentOS

在 CentOS 中

ln -sf /usr/local/bin/python2.6 /usr/local/bin/python
ln -sf /usr/local/bin/python2.6 /usr/bin/python

To check version do:

要检查版本,请执行以下操作:

python -V

Then to fix yum "No module named yum", you should do:

然后要修复 yum “No module named yum”,您应该执行以下操作:

vi `which yum`

and modify #!/usr/bin/pythonto #!/usr/bin/python2.4

并将#!/usr/bin/python修改为#!/usr/bin/python2.4