6

I am new to Linux and going through my installed folder I can see there are four different Python folders in the directory list.

python python2.7 python3 python3.2

Do we need all the four versions or should I remove the others and keep only the latest?

Also don't the older versions get removed automatically when newer versions are installed as in Windows?

SDsolar
  • 2,378
  • 8
  • 26
  • 43
SteveIrwin
  • 1,710
  • 2
  • 18
  • 31

4 Answers4

8

If you look in /usr/bin, there are actually only two versions installed:

$ ls -la /usr/bin/python*
lrwxrwxrwx 1 root root       9 Jun  5 23:08 /usr/bin/python -> python2.7
-rwxr-xr-x 1 root root 2679344 May  6 19:31 /usr/bin/python2.7
lrwxrwxrwx 1 root root       9 Aug  2 18:04 /usr/bin/python3 -> python3.2
lrwxrwxrwx 1 root root      11 Jul  6 09:52 /usr/bin/python3.2 -> python3.2mu
-rwxr-xr-x 1 root root 2612900 Jul  6 09:52 /usr/bin/python3.2mu
lrwxrwxrwx 1 root root      11 Aug  2 18:04 /usr/bin/python3mu -> python3.2mu

The entries marked l at the start are links; they're just pointers to executable files.

As has already been said, you need both versions and don't mess with stuff in there ...

Mark Booth
  • 4,410
  • 2
  • 31
  • 43
scruss
  • 9,117
  • 1
  • 25
  • 36
3

Python 3 is a backward incompatible upgrade of the language. As already mentioned, so much was changed, that most programs won't work on Python 3 without modifications. Even worse, many Python libraries are not compatible with Python 3 yet.

This is why at least two versions are needed - legacy Python 2.x and new Python 3.x. This is exactly what you have on Debian systems. You have 4 different paths you can use to run Python:

  • python2.7 - it's version 2.7 of Python, the newest version of 2.x line.
  • python3.2 - it's version 3.2 of Python, the newest version of 3.x line available in Debian (3.3 is not yet available).
  • python - it's a default python interpreter. It's a symbolic link to some version that is considered default one. Currently - in Debian - it's still Python 2 so it points to 2.7.
  • python3 - it's the most up to date Python 3 interpreter available in Debian. Currently it symlinks to a 3.2 version of interpreter.

Conclusion

A lot of packages depend on Python 2.x so you should not remove it. There may be some packages that depend on Python 3.x so you also probably don't want to remove this one.

Krzysztof Adamski
  • 9,605
  • 1
  • 38
  • 53
2

Python3 isn't really an upgrade of Python2. Only trivial programs will run without at least being run through 2to3.

On the other hand, when there are minor updates, eg 2.7.2 -> 2.7.3 the 2.7 will be updated to the new version and the older one gets deleted. This is generally ok as there isn't supposed to be backward incompatible changes (I won't say this has never happened though)

You won't usually see say 3.3 being added to the repository between releases, but when it does show up and you upgrade, the 3.2 will remain installed in case you depend on that specific version. Pure Python code that runs on 3.2 should be mostly ok on 3.3, but C libraries may not work without being rebuilt.

John La Rooy
  • 12,005
  • 9
  • 48
  • 77
0

The answer to the last part of your question, "Also don't the older versions get removed automatically when newer versions are installed as in Windows?"

The answer is a clear and emphatic No.

Older versions do not get removed when new versions are installed.

Too much of our software ecosystem has been built on top of Python 2.x for it to be expendable. To remove it would break a lot of our commands.

Plus, Python 3 offers very little that is attractive to the Python 2.7 programmer. If you find you need those features then you have the option of using Python3. If not, people like me will stay with Python 2.x

As has been mentioned in the other answers, they are not really the same language anymore.

It is like the difference between programs that could work with Windows 98 but couldn't work on Windows 2000. Programs that you used under Win98 had to be re-released after being compiled for 2000 (32 bit). Windows 2000 did not catch on in the consumer market because it would cause those consumers to need to buy their favorite products again. Only with Windows XP did they finally make it so programs of both types could run under the same Windows OS. We are fortunate that Microsoft has learned from that lesson and that 32-bit and 64-bit programs can both be run on any modern version of Windows.

Back to the question in your title, "Do we need multiple versions of Python?" - it depends on what software you want to be able to use. One standout example is flightgear. Without Python3 it will not run.

SDsolar
  • 2,378
  • 8
  • 26
  • 43