How can I remove python 3.6 installed from deadsnakes PPA after upgrade to Ubuntu 18.04?

7,790

Solution 1

After reading the comments below the question I successfully reinstalled python3.6 and want to share with you how I did it.

  1. 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.
  2. I made sure that the deadsnakes PPA is deactivated.
  3. 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
    
  4. I ran sudo apt-get update and sudo 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.

Solution 2

For those like me who confirm to delete the 200 packages, I've been able to use a non graphic session (Ctrl+Alt+F1) to reinstall gnome (or cinnamon, I had both installed and both were removed when I remove python3.6).

Share:
7,790

Related videos on Youtube

Oli4
Author by

Oli4

Updated on September 18, 2022

Comments

  • Oli4
    Oli4 almost 2 years

    On Ubuntu 16.04 I installed Python 3.6 from the deadsnakes PPA. Now I upgraded to Ubuntu 18.04 which builds on top of Python 3.6 but instead of removing the old version of Python 3.6 it kept the version from the deadsnakes PPA which leads to dependency issues if I want to install anything related to python. For example, if I run sudo apt install python3.6-venv:

    The following packages have unmet dependencies:
    python3.6-venv : Depends: python3.6 (= 3.6.5-3) but 3.6.6-1+xenial1 is to be installed
    

    Is there a safe way to remove 3.6.6-1+xenial1 without removing everything which depends on it to install the default Python 3.6? Otherwise, I would have to reinstall Ubuntu from scratch.

    A related question is impossible to install with apt-get, python missing Unfortunately, the only answer given recommends manually removing and reinstalling python3.6 which would lead to the removal of about 218 packages. This is what I would like to circumvent. sudo apt-get remove python3.6:

    The following packages will be REMOVED:
    apparmor apport apport-gtk aptdaemon apturl apturl-common asymptote atom
    cdbs command-not-found compiz compiz-gnome dh-python firefox
    foomatic-db-compressed-ppds gconf2 gdm3 gedit gedit-common gir1.2-ibus-1.0
    gnome-control-center gnome-menus gnome-online-accounts gnome-orca
    gnome-shell gnome-software gnome-software-plugin-snap gnome-terminal
    ...
    
    • Ray
      Ray almost 6 years
      Under similar circumstances that I have seen, it is ok to uninstall the deadsnakes version of Python 3.6. Yes, it will cause all 218 packages to be removed, but right after, you'll install them back again. (Of course, in-between, remember to remove the entry in /etc/apt.) With apt, I have had scenarios where I uninstall something only to reinstall it back. As long as you still have a working system, it'll be ok... Perhaps someone else can give you alternative advice?
    • wjandrea
      wjandrea almost 6 years
      @Ray There's a way to uninstall a package without uninstalling its dependencies. I think it's an option called --force-dependencies but I can't check right now.
    • doug
      doug almost 6 years
      You should see what packages are currently installed from that ppa (synaptic could find easily). Any that can be removed without any potential issue should be. For any remaining locate and download the bionic package(s), if multiple put them in an empty folder & install all at once with dpkg, sudo dpkg -i *.deb A single package can just be installed directly with apt or dpkg. (try apt first) Current packages for bionic can be found easily with a web search of name..
    • WinEunuuchs2Unix
      WinEunuuchs2Unix almost 6 years
    • Ray
      Ray almost 6 years
      @wjandrea Thanks for letting me know! Though, back to Oli4's question...I'm not sure what's the "harm" in removing 218 packages. No personal data is associated with it such removal (i.e., no work is lost). One scenario I can think of is that there's a limit on Internet bandwidth and want to minimize re-transferring files that are already there. If it weren't for that, I don't see a problem with giving it a try... (Perhaps I'm missing something?)
    • Oli4
      Oli4 almost 6 years
      Thank you all for your comments. @Ray My main concern is that I will break Ubuntu because system relevant packages are getting removed. All this stuff from gnome getting removed for example. Will this not break Ubuntu?
    • Ray
      Ray almost 6 years
      @Oli4 To be 100% honest with you, I don't know. But it is possible to boot into rescue mode with minimal services loaded and run apt to install packages. However, I don't think it'll get to that. Once you remove it, literally, you're installing it all back again. Even if you are in gnome, when you uninstall gnome, it doesn't die immediately; since it has been loaded into memory. If that is what you're worried about, you can use a command-line shell (i.e., CTRL-ALT-F2 at the login screen) and do it there?
    • Ray
      Ray almost 6 years
      ...it might be worrying if this was a cloud-based server and you don't have physical access to it. (i.e., to reboot into rescue mode with an Ubuntu boot disk plugged in) Even so, I do understand your hesitation; many things depend on Python. But I don't think Ubuntu will "break" as bad as something critical like the kernel itself. Sorry that I cannot give you more confidence! Other options mentioned so far will probably work; but given their complexity, I was curious what were your reasons for avoiding the obvious, simpler option.
    • wjandrea
      wjandrea almost 6 years
      The command I was thinking of is sudo dpkg --remove --force-depends python3.6
    • Zanna
      Zanna almost 6 years
      @Ray I've reinstalled Ubuntu more than once because it was the easiest way to fix a terrible mess left by some irreversible package removal operation. Oli4's caution is justified. If you're fine with reinstalling you can mess with package-management to your heart's content. Otherwise it's better to not remove things with many dependencies like python
    • Ray
      Ray almost 6 years
      @Zanna I did not say Oli4's caution wasn't justified. And I have re-installed Ubuntu 4 times in one day on a machine just last week -- I know what you mean. What I mean is if you bypass the graphical interface, then you've reduced many problems. Many of the dependencies we're worried about are loaded in to memory and will be there during a quick uninstall, reinstall. So, that includes many of the dependencies we're talking about. I am not suggesting uninstalling and then logging out or rebooting! Because memory would be cleared and, yes, some problems may result.
    • Ray
      Ray almost 6 years
      In my humble opinion (no offense to Oli4...) but the "terrible mess" happened by jumping ahead to Python 3.6 while on Ubuntu 16.04. So, the terrible mess isn't what will happen from now; but what already happened before. What we're talking about is minimizing the damage from here on out. Various alternative suggestions above are great and may work...I never said "my suggestion was the best". But there are pros and cons to all approaches. I won't say one is better than the other -- I'm only suggesting what I would do if I was in the same situation as Oli4's.
  • Ilya Palopezhentsev
    Ilya Palopezhentsev over 3 years
    Thanks, it helped me with failed 18.04->20.04 upgrade too, with the difference of 3.8 instead of 3.6 in all cmd lines. As I see, it was deadsnakes ppa repository which I had on 18.04 for newer python version - in the end it botched the whole 20.04 upgrade, I had to reinstall packages like samba again - it was only possible after following your suggestion