10

I have multiple versions of python installed in ubuntu (precise) for various reasons and uses. I have python 2.7 and python 2.6. I need to make python 2.6 the default and not python 2.7. I updated python symlink to point to python2.6. That will only give me commandline access straight to python2.6. but when I install some package from aptitude, it goes straight to python2.7 compatible stuff because somewhere in the OS, its sees that as the default. How should I change this ?

P.S : I know the workaround of installing from package's source code. But its not easy to get the source code always and not all are generous.

King
  • 1,170
  • 2
  • 16
  • 33
  • Numerous similar posts: http://stackoverflow.com/q/5846167/623518, http://stackoverflow.com/q/9349831/623518, http://stackoverflow.com/q/7679674/623518... – Chris Aug 01 '12 at 09:57
  • 2
    Only one of those is for Ubuntu, and it has the correct answer at a very low score. – tripleee Aug 01 '12 at 10:18
  • @Chris : Numerous similar questions but none seemed to answer it really the way it has to be. As pointed above, the correct answer is somewhere hidden beyond visibility. – King Aug 01 '12 at 10:35
  • Well perhaps we should improve some of the other questions, rather than re-asking the question. [This](http://stackoverflow.com/a/7679735/623518) is probably the best IMO: if you want multiple installations of Python on the same machine, use [virtualenv](http://pypi.python.org/pypi/virtualenv). – Chris Aug 01 '12 at 10:48
  • I wire scripts into makefile for testing purposes and adding lines to move virtualenv won't do it good because it will become system-specific. That's the only reason, I din't take that path. – King Aug 01 '12 at 11:35

1 Answers1

7

On Ubuntu and other Debian-derived distributions, the proper way to define which Python version to run system-wide is with sudo update-alternatives --config python. See also http://www.stylesen.org/python_27_debian_squeeze_60

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • 11
    @King: Before you do this, please be sure to read the comments at the end of the [link](http://www.stylesen.org/python_27_debian_squeeze_60). Using `update-alternatives` this way is likely to screw up your system. – unutbu Aug 01 '12 at 10:30
  • 2
    With the above command I got: "update-alternatives: error: no alternatives for python" although my /usr/bin shows both 2.7 and 3.4 versions. – coder.in.me Sep 19 '14 at 04:52
  • 2
    In Debian, `python3` is distinct from `python` and thus not an alternative. The differences between 2 and 3 are significant enough that this would not work anyway. – tripleee Sep 19 '14 at 05:01