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
  • 1
    @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.
    – wjandrea
    Aug 19, 2018 at 14:50
  • 1
    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..
    – doug
    Aug 19, 2018 at 16:08
  • 1
    This might help: stackoverflow.com/questions/50397705/… Aug 19, 2018 at 20:14
  • 1
    @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
    – Zanna
    Aug 27, 2018 at 5:15
  • 1
    @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
    Aug 27, 2018 at 13:07

3 Answers 3


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.

  • 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 Oct 4, 2020 at 10:42

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).


It's risky to remove important packages, so don't do that.

First, I disabled the deadsnakes PPA by editing /etc/apt/sources.list.d/deadsnakes.list and commenting out the lines.

apt-get can downgrade a set packages to a specified version:

sudo apt-get install idle-python3.9=3.9.2-1 libpython3.9=3.9.2-1 libpython3.9-dev=3.9.2-1 libpython3.9-minimal=3.9.2-1 libpython3.9-stdlib=3.9.2-1 python3.9=3.9.2-1 python3.9-dev=3.9.2-1 python3.9-minimal=3.9.2-1 python3.9-venv=3.9.2-1

I used this script to generate the command to downgrade python. You can change the settings to match your problem.

packages=`dpkg -l '*python*' | grep $from_release | grep $from_version | awk '{print $2}' | sed 's/:amd64//' | sed "s/\$/=$to_version/"`
set -x
sudo apt-get install $packages

I then added settings to hopefully prevent this happening again, in /etc/apt/preferences.d/99dontbreakdebian. I'm using Debian bullseye / testing, so my file is not suited for Ubuntu. You can see options for pin with the apt-cache policy command.

DO NOT JUST COPY THIS FILE. You need to understand it, adjust for your setup, and test it carefully:

Package: *
Pin: release o=Debian,a=experimental
Pin-Priority: 1

Package: *
Pin: release o=Debian,a=unstable
Pin-Priority: 100

Package: *
Pin: release a=focal
Pin-Priority: 100

Package: *
Pin: release o=LP-PPA-deadsnakes
Pin-Priority: 100

Package: *
Pin: origin ppa.launchpad.net
Pin-Priority: 100

Package: *
Pin: release o=Debian
Pin-Priority: 990

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.