简体   繁体   English

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

[英]Change default Python version from 2.4 to 2.6

I'm wanting to use some newer software that requires Python 2.6 , and we currently have both 2.4 and 2.6 installed 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.6 as the default python ? 如何将其切换为使用2.6作为默认python

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(替换旧的硬链接)创建一个符号链接。

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. 并重新启动shell。

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

Add an alias for the command "python" in the your bash shell's startup file. 在bash shell的启动文件中为命令“python” 添加别名 DON'T change a symbolic link from /usr/bin/python, because changing the default Python (in Ubuntu or Linux Mint for example) may break your system 不要从/ usr / bin / python更改符号链接,因为更改默认Python(例如在Ubuntu或Linux Mint中) 可能会破坏您的系统

PS: read other answers PS:阅读其他答案

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“没有名为yum的模块”,你应该这样做:

vi `which yum`

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

I had similar problem when using meld, I simply renamed the one under local and it worked. 我在使用meld时遇到了类似的问题,我只是在本地重命名了它,它起作用了。 Not a good solution I know, but I can always take it back. 我知道这不是一个好的解决方案,但我总能把它拿回来。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM