Wai Tong
Wai Tong

Reputation: 339

Ubuntu, how do you remove all Python 3 but not 2

I have recently get hold of a RackSpace Ubuntu server and it has pythons all over the place:

iPython in 3.5, Pandas in 3.4 &2.7, modules I need like pyodbc etc. are only in 2,7

Therefore, I am keen to clean up the box and, as a 2.7 users, keep everything in 2.7.

So the key question is, is there a way to remove both 3.4 and 3.5 efficiently at the same time while keeping Python 2.7?

Upvotes: 15

Views: 148153

Answers (8)

Somesh Mahajan
Somesh Mahajan

Reputation: 286

Uninstall python3

sudo apt-get remove python3.5

sudo apt-get remove --auto-remove python3.5

sudo apt-get purge python3.5

sudo apt-get purge --auto-remove python3.5

more details refer https://gist.github.com/soos3d/c4fe369a278d94fa5acc1ca22f1348c8

Upvotes: 0

user25051166
user25051166

Reputation: 59

Assuming you want to do this on a remote ssh or xrdp / vnc server, I've done it many times on my Google Cloud and Amazon AWS Server and it's pretty safe. It really depends on your own server specifications. This is how I would do it:

sudo apt remove python3 --purge

As mentioned above, don't try in your local desktop environment or you might need a reinstallation later.

Upvotes: 1

Germain67
Germain67

Reputation: 718

EDIT: As pointed out in recent comments, this solution may BREAK your system.

You most likely don't want to remove python3.

Please refer to the other answers for possible solutions.

Outdated answer (not recommended)

sudo apt-get remove 'python3.*'

Upvotes: 10

Saurabh Verma
Saurabh Verma

Reputation: 197

neither try any above ways nor sudo apt autoremove python3 because it will remove all gnome based applications from your system including gnome-terminal. In case if you have done that mistake and left with kernal only than trysudo apt install gnome on kernal.

try to change your default python version instead removing it. you can do this through bashrc file or export path command.

Upvotes: 2

sammy mutahi
sammy mutahi

Reputation: 17

Its simple just try: sudo apt-get remove python3.7 or the versions that you want to remove

Upvotes: -3

Wai Tong
Wai Tong

Reputation: 339

So I worked out at the end that you cannot uninstall 3.4 as it is default on Ubuntu.

All I did was simply remove Jupyter and then alias python=python2.7 and install all packages on Python 2.7 again.

Arguably, I can install virtualenv but me and my colleagues are only using 2.7. I am just going to be lazy in this case :)

Upvotes: 9

SHISH PAL
SHISH PAL

Reputation: 71

First of all, don't try the following command as suggested by Germain above.

   `sudo apt-get remove 'python3.*'`

In Ubuntu, many software depends upon Python3 so if you will execute this command it will remove all of them as it happened with me. I found following answer useful to recover it.

https://askubuntu.com/questions/810854/i-deleted-package-python3-on-ubuntu-and-i-have-lost-dashboard-terminal-and-un

If you want to use different python versions for different projects then create virtual environments it will be very useful. refer to the following link to create virtual environments.

Creating Virtual Environment also helps in using Tensorflow and Keras in Jupyter Notebook.

https://linoxide.com/linux-how-to/setup-python-virtual-environment-ubuntu/

Upvotes: 7

Hazem
Hazem

Reputation: 550

Removing Python 3 was the worst thing I did since I recently moved to the world of Linux. It removed Firefox, my launcher and, as I read while trying to fix my problem, it may also remove your desktop and terminal! Finally fixed after a long daytime nightmare. Just don't remove Python 3. Keep it there!

If that happens to you, here is the fix:

https://askubuntu.com/q/384033/402539

https://askubuntu.com/q/810854/402539

Upvotes: 22

Related Questions