maxirodr
maxirodr

Reputation: 470

ubuntu broken python installation by mistake

I've tried to update Python and I didn't know about isollation of version instead delete the versions, so, I've deleted all of my Python version inside my Ubuntu 16.04 VPS. Now i'm not able to install nothing trough apt-get.

:

root@vps15:/# apt-get install --reinstall python3.5
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
 dh-python : Depends: python3:any (>= 3.3.2-2~)
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

I tried to install manually to source Python 2.7 to /usr/lib and that works now, but the problem now is this dependency: "dh-python".

# apt-get install python3.5-minimal
Reading package lists... Done
Building dependency tree      
Reading state information... Done
python3.5-minimal is already the newest version (3.5.2-2ubuntu0~16.04.5).
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
 python3.5-minimal : Depends: libpython3.5-minimal (= 3.5.2-2ubuntu0~16.04.5) but it is not installable
                     Recommends: python3.5 but it is not installable
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).

I've tried all the methods listed and I can't fix the dependencies.

Before trying the fixing, the problem was Python2.7 instead python3, now python3 by manual installation didn't fix the problem.

Upvotes: 8

Views: 17778

Answers (2)

Jarppiko
Jarppiko

Reputation: 51

Thanks for pointing me to the root cause. For me the issue was broken distro_info package installed by pip and pip itself was so broken that I could not uninstall the package via pip uninstall. I removed /usr/local/lib/python3.8 so do-release-upgrade would use the original Ubuntu packages under /usr/lib/python3.8. This solved the issue. I was updating from 20.04 => 22.04.

Upvotes: 1

maxirodr
maxirodr

Reputation: 470

After some more research, I've founded a post related to Debian. Handling some modifications for Ubuntu 16.04, tried this guide and works everything now:

Step 1.

cd /tmp
apt-get download libpython3.5-minimal
apt-get download python3.5-minimal
apt-get download python3-minimal
apt-get download libpython3.5-stdlib
apt-get download python3.5

Step 2.

rm -rf /usr/local/lib/python3.5*
rm -rf /usr/local/bin/python3.5*
update-alternatives --remove python3 /usr/local/bin/python3.5
hash -r  # removes cached python3 binary path

Step 3.

cd /tmp
dpkg-deb -x libpython3.5-minimal_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x libpython3.5-stdlib_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x python3.5-minimal_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x python3.5_3.5.2-2ubuntu0~16.04.13_amd64.deb missing
dpkg-deb -x python3-minimal_3.5.1-3_amd64.deb missing

Step 4.

cd /tmp/missing
ls -lR /tmp/missing  # if you are curious about overwriting your HD
sudo cp -rpfv /tmp/missing/*  /

Step 5.

python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Import and test new version:

>>> import sys
>>> print(sys.version_info)
sys.version_info(major=3, minor=7, micro=3, releaselevel='final', serial=0)
>>>
>>> quit()

Step 6.

rm -rf /tmp/missing

Step 7.

dpkg -s -a python3.5 | grep  reinstreq
# Any listing also needs to be reinstalled along with python3
apt-get install --reinstall python3

Step 8.

apt-get autoclean
apt-get autoremove
# (see the packages that will autoremove, you need to reinstall it again after: apt-get install --fix-broken --reinstall <<packages>>)

Step 9.

Try to install common prop.

sudo apt install software-properties-common

If it works, now the installation is done.


I've tried this for Ubuntu 16.04, with working Python2.7 installation but not with Python3, or Python3.5. The original installation I've was for Python3.5, that's why tried to install that version instead newest.

Upvotes: 27

Related Questions