24

I have successfully installed python 3.3 on Ubuntu 12.10. Since I don’t need multiple versions of python, I want to remove the existing python 2.7. When I try to do that, using

sudo apt-get remove python2.7

Ubuntu warns me that there are tons of system dependent components which will also be removed. It looks really scary.

So, is there a way to remove python 2.7 without removing the system dependent components, or can I direct those dependents to use python 3.3?

2
  • 2
    I would not recommend it. Python version are not at all so compatible, so older scripts could have experience problems if you will not have the correct version.
    – tikend
    Jul 1, 2013 at 13:44
  • you are right, python3.3 has declared that it is incompatible with python 2.7. So, I better just keep it. Thanks for the advice! Jul 1, 2013 at 13:49

3 Answers 3

29

You can't.

From the Ubuntu wiki / Python:

Longer term plans (e.g. 14.04)

Move Python 2 to universe, port all Python applications in main to Python 3. We will never fully get rid of Python 2.7, but since there will also never be a Python 2.8, and Python 2.7 will be nearly 4 years old by the time of the 14.04 LTS release, it is time to relegate Python 2 to universe.

This means that a lot of base packages have hard dependencies on 2.7 and it will still take a lot of time tot get things migrated. Note that Python 3 has numerous backwards incompatible changes -- it's not a regular package upgrade.

If you really want to get rid of Python 2.7, you'll have to wait for the 14.04 release, but there's no guarantee.

4
  • 3
    It's 16.04, now.
    – muru
    Apr 21, 2016 at 12:36
  • 1
    It's 18.04, now. Sep 8, 2019 at 17:51
  • 1
    It's 19.04 fu#!& now
    – Genarito
    Oct 21, 2019 at 15:33
  • 1
    It's 20.04, now. Apr 20, 2021 at 10:08
15

Came here in 2019 because I develop in Python3 by default and came to the same conclusion as OP after seeing what'd be removed after running apt purge python

Since what I really wanted was to call Python3 with just python, I ran

sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python

This way, if Python2.7 is still needed, it can be called explicitly with python2.7 while simply calling python will default to Python3 because of the symbolic link.

I don't have any bash level scripts that call python2.7 with python so this change wouldn't be disruptive - while other systems would need their scripts adjusted accordingly if they did.

The main barrier to a distribution switching the python command from python2 to python3 isn't breakage within the distribution, but instead breakage of private third party scripts developed by sysadmins and other users.

- The "python" Command On Unix-Like Systems

This answer isn't a direct response to OP, but as someone who had a similar question this is the functionality I was looking for when I was thinking of removing 2.7. Rather than delete, just prioritize which one gets to use python.

11
  • 1
    It strikes me as a bad idea. Any old scripts made for Python 2 will call /usr/bin/python, whilst almost every script made for Python 3 will be aware of the change, and call python3 at the present time. Letting python point to python2.7 is less likely to break things.
    – vidarlo
    May 29, 2019 at 21:59
  • I'd say it depends on the environment, like I said I don't make scripts that require python2 and work in 3 - while if I made a change like this on one of our stations at work running automated scripts it would be very disruptive.
    – sanigirl
    May 29, 2019 at 22:04
  • Are there specific system processes you would be able to list that call /usr/bin/python? I'm always open to changing my mind when presented with new information
    – sanigirl
    May 29, 2019 at 22:07
  • 1
    On the system I checked, there's 39 that does not make a explicit reference to python3 or python2. All of those are probably python2. This of course depends on what you have installed, but I see no big reason to do this either...
    – vidarlo
    May 29, 2019 at 22:21
  • 1
    Remove the symbolic link and reinstall the python binary
    – sanigirl
    Jul 31, 2020 at 18:52
7

You can't, and you don't really want to.

Python changed drastically between 2.7 and 3.0, and broke backward compatibility. Python scripts that were written for 2.7, which are used to support a large amount of the system's infrastructure, won't necessarily work properly with Python 3.x. Those scripts need to be updated to work with the new version, and until that happens, you'll need to keep Python 2.7 around.

This is why you notice such a large number of dependencies on the old Python - the system depends on it. Besides, there's no harm in having both versions of Python installed on the same system. And you may come across applications in the future that still use Python 2.7, so keeping it around is a good idea.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .