How to fix python3 - after messing it up?

6,018

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.

Share:
6,018

Related videos on Youtube

Ossi Viljakainen
Author by

Ossi Viljakainen

Updated on September 18, 2022

Comments

  • Ossi Viljakainen
    Ossi Viljakainen over 1 year

    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?

    • noobninja
      noobninja over 4 years
      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.
    • Ossi Viljakainen
      Ossi Viljakainen over 4 years
      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: