How can I remove python 2.7 after installing python 3.3?

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?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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.

Solution 2

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.

Solution 3

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.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply