Change default Python version from 2.4 to 2.6

PythonLinuxVersion

Python Problem Overview


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:

$ 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?

Python Solutions


Solution 1 - 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).

Solution 2 - Python

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

so open the startup file: emacs ~/.bashrc

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

and restart the shell.

Solution 3 - Python

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

Solution 4 - Python

Add an alias for the command "python" in the your bash shell's startup file. 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

P.S.: read other answers

Solution 5 - Python

In 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:

vi `which yum`

and modify #!/usr/bin/python to #!/usr/bin/python2.4

Solution 6 - Python

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.

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKristopher IvesView Question on Stackoverflow
Solution 1 - PythonunutbuView Answer on Stackoverflow
Solution 2 - PythonJianView Answer on Stackoverflow
Solution 3 - PythonC WalkerView Answer on Stackoverflow
Solution 4 - PythonLinux userView Answer on Stackoverflow
Solution 5 - PythonSlipstreamView Answer on Stackoverflow
Solution 6 - PythongezgingunView Answer on Stackoverflow