-1

I have a Ubuntu 20.04 LTS version(I am new to Ubuntu), recently I wanted to install the latest version of python i.e. python3.10.0 but was not able to so I looked online and followed many methods but not remember which one worked hence, I won't be able to tell what I used.Then the next day when I tried to open the terminal it was not working so I looked up the internet and it said that it might be because of the recent things I installed and as the latest thing I did was to install python and I remembered a warning regarding the installation of python3.10.0 that came up during the installation process but I ignored it so, I thought of removing python from the system I did that using something as Clt+Alt+F3 but I messed up the python of the OS. Since then many applications are not opening including terminal, is there a way to fix this without installing Ubuntu20.04 again because I don't want to do the process again and then install the third party packages once more and also my important files will be lost. I want a solution that will repair whole OS without disturbing much of apps and packages(It is okay if some apps and packages are removed but not all)

Note: I have synaptic package manager,dconf-editor,gdebi package manager if needed I can use them.

Edit: If everything is removed it is okay and I have created backup for files but don't want to install it over again.

Archisman Panigrahi
  • 28,338
  • 18
  • 105
  • 212
  • 2
    Numerous parts of Ubuntu rely on the version of python that's distributed with your version of Ubuntu. Installing a different version was a big mistake. You are new to Ubuntu and this mistake will cause widespread problems. You should reinstall. It won't take as long as it will take you to fix all the little problems. It's a good thing you have backups – Nmath Nov 25 '21 at 04:55
  • 1
    If you removed python3 from the system in your attempts to fix things you'll likely find gdebi & other tools you had are no longer there; or are not operational (or may do damage instead of helping you); eg. look at https://packages.ubuntu.com/focal/gdebi and you'll see it depends on python3 being present & working (with it being the version the system came with too usually). You can re-install a desktop system without starting again (do use any option that performs format!) – guiverc Nov 25 '21 at 04:55
  • 2
    If you need a specific python version for a task, set up an environment or use a VM or other container so that it does not wreck your system – Nmath Nov 25 '21 at 04:57
  • 1
    Try this https://askubuntu.com/a/1377304/124466 If it does not work, you will have to reinstall. – Archisman Panigrahi Nov 25 '21 at 05:18
  • 1
  • Thank you for trying your best but nothing is working, I guess I will have to install it again – mrx king Nov 25 '21 at 10:51
  • 1
    Your apt logs (/var/log/apt/history.log) should tell what you did exactly did; and thus what will reverse it if you look re: package changes, but until you've re-installed at least python3-minimal (with the correct python3 version & reverse and incorrect version changes) you'll have to limit yourself only to base programs that don't use python (ie. wget & dpkg etc. will still work); even if easier front-ends aren't currently working as they need python3 fixed first. Again re-install is faster & can auto-reinstall manually installed packages from Ubuntu repos & not touch your files. – guiverc Nov 25 '21 at 11:24
  • 1

2 Answers2

0

I accidentally deleted python3 under /usr/lib on Ubuntu 20; you could've messed it one way or another as well; my system afterwards won't update, launch the terminal or run software updates. You do NOT need to reinstall your Ubuntu.

Here is how I solved the problem:

  1. boot your system from a USB Ubuntu stick
  2. Do not install, choose to "Try Ubuntu"
  3. Launch the terminal on your Ubuntu (which you are running in try mode on the USB stick).
  4. Open two tabs in terminal:
    • one that is pointing to your local Ubuntu stick path /usr/lib
    • another pointing to "Other locations" where you point to the local drive of your computer's /usr/lib. Typically under /media/some hash code/../usr/lib
  5. from properties, copy the path of your /usr/lib of your mounted drive on you PC. It would be something under /media path.
  6. cp -r /usr/lib/python3 into your mounted local drive path on your PC where /usr/lib is. If you had messed it up, delete the local one, and copy the one from the usb stick.
  7. Shutdown your running Ubuntu (try-mode on USB stick) and Start Ubuntu on your PC as usual.
  8. You will need to fix some apport dependencies that are installed already on your system, but are not yet hooked to your system's python3 environment. To do that:
    1. Open the original terminal that comes with Ubuntu. You can do that now from the applications' launcher, or Ctrl+Meta+Alt+F3 to go to tty terminal (to go back to Gnome Ctrl+Meta+Alt+F1).

    2. When you open the terminal, you get an error message before the prompt. Read through, and it is already naming a missing package.

    3. The named missing package(s) are not pip installable, rather apt installed. Install the respective package with the command:

      apt -f install --reinstall <package name>
      
    4. Then close the terminal, and reopen again the terminal. You will need to do that incrementally. So, you will get another name for a missing python package being imported by python but not found. Again, install it the same way with apt as above. Incrementally doing so until all errors are gone, and all hooks are re-established.

    5. Finally, run:

      sudo apt install --reinstall ubuntu-desktop
      

      P.S. note that, if you had gnome-tweaks installed, you will need to reinstall it as well:

      sudo apt install --reinstall gnome-tweaks
      

And you are done.

matigo
  • 22,138
  • 7
  • 45
  • 75
-1

Try this:

$ apt -f install Reboot. If it's still not right, try: $ dpkg-reconfigure -a Reboot. It should be working for sure, unless you messed up the package database in /var Let us know how it goes. Write down all the errors, in case we need them to further assist you.

I wouldn't worry. I used to get into a mess all the time. It's how you learn!

Brian
  • 334
  • I tried both the options but every time a lot of errors come most of them say that some python packages are not properly installed and in the end it comes like this “E: Sub-process /usr/bin/dpkg returned an error code(1)” – mrx king Nov 25 '21 at 10:57
  • Try this, $ touch test.txt $ apt -f install > test.txt $ dpkg-reconfigure -a >> test.txt Notice there are (2) '>' in the second one. afterward, paste the file to a pasteboard and put the link to it in your question. Also, try $ ls /var/cache/apt/archives > list.txt and paste that one too. See if there are any python packages in list.txt. Install them with $ dpkg -i --force-depends <full path and file name - extension> – Brian Nov 29 '21 at 01:43
  • I tried the commands but every time it says permission denied in both $ touch test.txt and ls/var/cache/apt/archives > list.txt what shall I do next? – mrx king Nov 29 '21 at 05:04
  • Shall I format my laptop and install ubuntu again because my work is stuck because this issue as the apps that I use for work are not working .. ? – mrx king Nov 29 '21 at 05:12
  • If time is a factor, and your not fast at Linux yet, it might make sense to reinstall. You need to use sudo for permission denied errors. – Brian Nov 30 '21 at 05:02
  • @mrxking no, don't do that, you should not loose hope – Error404 Dec 08 '21 at 07:33
  • @Brian What do you even mean? By apt -f install ? What will it even do in this case? – Error404 Dec 08 '21 at 07:34
  • apt -f install is designed to rescue a system with package dependency problems. It is so ubiquitous I wrongly assumed my meaning was intuitively obvious. Please accept my apology. – Brian Dec 09 '21 at 22:42