I had Ubuntu 16.04 LTS for a long time because I was thinking to use Kail Linux, but I never got to installing it so I just got Ubuntu 18.04 LTS. Now I want to know if its safe to remove python2 because now I have python 3.6 and I when I code in python its still uses python2. And if it's not safe to remove python2 then is there a way to just make Visual Studio Code use python3.
Ubuntu – Is it safe to remove python2 in ubuntu 18.04 LTS
python
Related Solutions
After reading the comments below the question I successfully reinstalled python3.6 and want to share with you how I did it.
- I made a backup of all my data which I would recommend to everyone trying this. Although it worked for me it may fail for some reason on your machine and you don't want to lose your data.
- I made sure that the deadsnakes PPA is deactivated.
I ran the following commands to remove the old version of python3.6 without removing all the dependencies and to directly install the default version.
sudo dpkg --remove --force-depends python3.6 python3.6-minimal libpython3.6-minimal libpython3.6-stdlib sudo apt-get install python3.6 python3.6-minimal libpython3.6-minimal libpython3.6-stdlib
I ran
sudo apt-get update
andsudo apt-get upgrade
before rebooting my machine.
Maybe this is overcomplicated but it worked for me. Thank you very much for your comments @wjandrea, @Ray, @Zanna.
Run
apt purge -s python2.7
where -s
is a simulation of what would happen.
and see for yourself what else you will lose.
On my system, Kubuntu 18.04, here's what I see:
The following packages were automatically installed and are no longer required:
gir1.2-appindicator3-0.1 gir1.2-gtk-vnc-2.0 gir1.2-keybinder-3.0 gir1.2-libosinfo-1.0 gir1.2-libvirt-glib-1.0 gir1.2-spiceclientglib-2.0
gir1.2-spiceclientgtk-3.0 gir1.2-vte-2.91 libgovirt-common libgovirt2 libgtk-vnc-2.0-0 libgvnc-1.0-0 libkeybinder-3.0-0 libphodav-2.0-0
libphodav-2.0-common libspice-client-glib-2.0-8 libspice-client-gtk-3.0-5 libusbredirhost1 libvirt-glib-1.0-0 spice-client-glib-usb-acl-helper
syslinux-common virt-viewer xsltproc
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
boot-repair* boot-sav* boot-sav-extra* glade2script* kubuntu-settings-desktop* python* python-asn1crypto* python-cairo* python-certifi*
python-cffi-backend* python-chardet* python-cryptography* python-dbus* python-enchant* python-enum34* python-gi* python-gi-cairo*
python-gobject* python-gobject-2* python-gtk2* python-gtkspellcheck* python-idna* python-ipaddr* python-ipaddress* python-libvirt*
python-libxml2* python-libxslt1* python-mutagen* python-openssl* python-pkg-resources* python-psutil* python-qt4-dbus* python-requests*
python-six* python-urllib3* python-xdg* python2.7* ranger* recoll* terminator* trash-cli* virt-manager* virtinst* zim*
0 upgraded, 0 newly installed, 44 to remove and 0 not upgraded.
I won't be removing python2.7.
Looking further into this, one can find out what is present in a clean installation of Ubuntu 18.04, as opposed to an upgrade from an earlier version, by looking at /var/log/installer/initial-status.gz. I have such a system.
From a terminal window, run:
$ zgrep "Package: python2.7" /var/log/installer/initial-status.gz
The search will be empty indicating that no package containing the string python2.7 was installed.
In your case, since you upgraded from 16.04 to 18.04:
If you do have python-2-7-15rc1 on your system, it means it was retained from your previous system as part of the upgrade or that you subsequently installed software that depended on it.
Either way, removing such a package in 18.04 is safe with the caveat that programs depending on it that you installed (a) when using the previous system (before the upgrade) or (b) after the upgrade maybe removed.
Keep in mind that during the life of 18.04, if you install something like calibre or gimp or variety or virt-manager, doing so will bring python2.7 back.
Best Answer
See for yourself safely using apt's
--simulate
flag:Read the proposed removals very carefully for applications and components that you don't want to remove.
If it turns out, after removing Py2, that you needed it after all...then it's trivial to reinstall.
WARNING: This answer applies only to Ubuntu 18.04 and newer. Earlier releases of Ubuntu have key components that depend upon Py2 (like apt). You may be very, very sorry if you remove Py2 in earlier releases of Ubuntu.