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

8
  • 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, 2021 at 4: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 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, 2021 at 4: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, 2021 at 4:57
  • 1
    Try this askubuntu.com/a/1377304/124466 If it does not work, you will have to reinstall. Nov 25, 2021 at 5:18
  • 1

2 Answers 2

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.

0
-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!

8
  • 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, 2021 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, 2021 at 1: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, 2021 at 5: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, 2021 at 5: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, 2021 at 5:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .