6

I was doing dist-upgrade to my system, but something didn't work as expected, and I also was running the upgrade while doing some other work.

Result python 3 got messed up and I can't run apt updates and cant upgrade the system

Error message:

dpkg: error processing package python3 (--configure):
 package is in a very bad inconsistent state; you should
 reinstall it before attempting configuration
Käsittelyssä tapahtui liian monta virhettä:
 python3
E: Sub-process /usr/bin/dpkg returned an error code (1)

My commandline history:

  276  sudo apt-get update && sudo apt-get dist-upgrade
  277  sudo apt-get dist-upgrade
  278  sudo apt autoremove
  279  sudo apt-get dist-upgrade
  280  man apt
  281  man dist-upgrade
  282  sudo do-release-upgrade
  283  /usr/bin/python3
  284  sudo do-release-upgrade
  285  sudo rm /usr/bin/python
  286  sudo ln -s /usr/bin/python2.7 /usr/bin/python
  287  sudo do-release-upgrade
  288  sudo ln -sf /usr/bin/python2.7 /usr/bin/python
  289  sudo do-release-upgrade
  290  sudo update-alternatives --remove-all python
  291  sudo update-alternatives --remove-all python3
  292  sudo ln -sf /usr/bin/python3.6 /usr/bin/python3
  293  sudo do-release-upgrade
  294  sudo apt-get install --reinstall python3
  295  sudo do-release-upgrade
  296  sudo dpkg --remove --force-remove-reinstreq --force-depends python3
  297  sudo apt-get -f install
  298  sudo do-release-upgrade
  299  sudo apt-get update
  300  sudo apt-get upgrade
  301  sudo apt-get reinstall python3
  302  man apt-get
  303  sudo apt-get install python3 --reinstall
  304  sudo ln -sf /usr/bin/python2.7 /usr/bin/python
  305  sudo apt-get install python3 --reinstall
  306  sudo do-release-upgrade
  307  history
  308  update-manager 
  309  sudo apt-get update && sudo apt-get upgrade
  310  sudo apt-get install python3
  311  sudo apt-get reinstall python3
  312* sudo dpkg --remove --force-remove-reinstr
  313  sudo dpkg --remove --force-remove-reinstreq python3 && sudo apt-get install python3

Now I do not remember anymore what I was actually doing, as this happened before my vacation, and now three weeks later I don't remember anymore what actually happened leading to this situation.

What should I do here?

Ossi Viljakainen
  • 489
  • 2
  • 5
  • 15
  • Some Python modules are used by the operating system, so a change to an important module could lead to instability. For example, if a user installs a module using pip, and the version of a dependency changes. So the existing Python installation tends to run better without modifications. For development, scripters should use a virtual environment or a container. The Anaconda distro is another option. $ sudo python3 -m venv some_env_name. – noobninja Dec 15 '19 at 22:37
  • Thanks for your comment, but it did not help me to get the system back to working condition.

    bash: /usr/lib/command-not-found: /usr/bin/python3:

    – Ossi Viljakainen Dec 18 '19 at 14:12

2 Answers2

12

I got it fixed by running sudo apt install --reinstall python3 python python3-minimal --fix-broken

Results of sudo apt install --reinstall python3 python python3-minimal --fix-broken:

  282  sudo apt-get --reinstall python3
  283  sudo apt-get install --reinstall python3
  284  sudo apt-get install --reinstall python3
  285  man apt-get
  286  apt list --installed
  287  apt list --installed |grep python
  288  apt list --installed |grep python > installed.python.txt
  289  ls list*
  290  ls inst*
  291  less installed.python.txt 
  292  pwd
  293  ls -l `which python`
  294  which python3
  295  which python
  296  ls -la /usr/bin/python
  297  history
  298  sudo apt-get install --reinstall python3
  299  sudo apt-get install --reinstall python
  300  sudo apt-get install --reinstall python3
  301  sudo apt-get install --reinstall python3-minimal
  302  sudo apt-get install --fix-broken
  303  sudo apt-get install --reinstall python
  304  sudo apt-get install --reinstall python3
  305  sudo apt-get install --reinstall python3-minimal
  306  sudo apt-get install --fix-broken
  307  sudo apt autoremove
  308  sudo apt-get update
  309  sudo apt-get upgrade
  310  sudo reboot

Now everything is working as expected.

karel
  • 114,770
Ossi Viljakainen
  • 489
  • 2
  • 5
  • 15
  • This worked for me too... I got into a similar mess... too messy to describe... but I got at least one python version working and then I did your line. – Yan King Yin Nov 02 '22 at 11:34
1

I had a similar problem, except there were multiple Python dependencies that threw this error (used sudo make install instead of sudo make altinstall on a freshly compiled Python version with a few problems.

I fixed it by running

sudo dpkg --remove --force-all python3-smbc python3-entrypoints python3-dbus python3-cairo:armhf python3-setuptools python3-apt python3-olefile  python3-debconf python3-yaml python3-xdg python3-wheel python3-cupshelpers  python3-six python3-pil:armhf python3-chardet python3-secretstorage python3-certifi python3-cryptography python3-gi python3-requests python3-idna python3-urllib3 python3-reportlab python3-keyrings.alt python3-keyring python3-crypto python3-asn1crypto python3-ptyprocess ssh-import-id python3-pexpect

and then proceeding with reinstallation.