How to Fix Python3 - After Messing It up?

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?

2

1 Answer

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.

Your Answer

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

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest