-1

I accidentally overridden /usr/bin/python and /usr/bin/python2 to /usr/bin/python3.8 and now I'm not able to reinstall and install anything because I get this error when using apt ModuleNotFoundError: No module named 'apt_pkg'.

I tried to reinstall python-minimal, python2.7 but without success.

I also tried to remove the python2.7 but I can't do that either because it depends on libgda which I cannot install either because my system does not recognize Python2.7.

Any idea how can I restore the old version of Python?

martineau
  • 119,623
  • 25
  • 170
  • 301
Honza Sedloň
  • 358
  • 10
  • 27
  • Did you try simply running `apt install python2.7`? A `ModuleNotFoundError` is inside of python itself, that's not part of installing python – Ofer Sadan Nov 11 '19 at 09:02
  • `python2.7` is already installed but I cannot find any executable file that I would copy to `/usr/bin`.. Every python file in `/usr/bin` starts `python3.8` – Honza Sedloň Nov 11 '19 at 09:05
  • **Do not uninstall Python 2.7!** Many system tools rely on it and you might damage your system beyond repair. – Klaus D. Nov 11 '19 at 09:10
  • Let me describe my process :D 1. Uninstall `python2.7` - denied, unmet dependency `libgda-5.0-common` which depends on `libjs-jquery` 2. Tried `sudo apt --fix-broken install` - denied, `Errors where encountered while processing: python-minimal` 3. Tried to reinstall `python-minimal` - Denied again because of `libgda` dependency – Honza Sedloň Nov 11 '19 at 09:11
  • Does this answer your question? [How to update-alternatives to Python 3 without breaking apt?](https://stackoverflow.com/questions/43062608/how-to-update-alternatives-to-python-3-without-breaking-apt) – Klaus D. Nov 11 '19 at 09:11
  • @KlausD. Yea well, I can't do it anyway, but thank you for the warning, I won't try it again – Honza Sedloň Nov 11 '19 at 09:11
  • @KlausD. Not really, I can't even find a single file that would run Python2.7 – Honza Sedloň Nov 11 '19 at 09:16
  • Related: https://unix.stackexchange.com/q/218911/17609 – moooeeeep Nov 11 '19 at 09:19
  • @moooeeeep Whoa, copy `python2.7` from Live CD actually worked, many thanks. Could you paste it as a solution? – Honza Sedloň Nov 11 '19 at 09:35

2 Answers2

2

If you just messed up with the symlinks (/usr/bin/python2 and /usr/bin/python) and the actual executable is still in place, you might be able to fix the problem by restoring the links:

sudo ln -s /usr/bin/python2.7 /usr/bin/python2 
sudo ln -s /usr/bin/python2.7 /usr/bin/python

Otherwise you can try to download a live-ubuntu and just copy the Python executable from the live OS back in place to fix your broken installation.

moooeeeep
  • 31,622
  • 22
  • 98
  • 187
0

follow this link to uninstall the python.

then make a fresh installment of python 2.7