4

I tried to uninstall python3.5 from my Ubuntu 16.04 by using the command sudo apt-get remove python3 within the directory /usr/bin. When I tried to install it again, using sudo apt-get install python3, I am getting the following error:

>> /usr/bin$ sudo apt-get remove python3
>> Reading package lists... Done
Building dependency tree
Reading state information... Done
Package 'python3' is not installed, so not removed
The following packages were automatically installed and are no longer required:
  gir1.2-glib-2.0 libexpat1-dev libgirepository-1.0-1 libpython3-dev libpython3.5-dev python-pip-whl python-pycurl python3.5-dev
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 61 not upgraded.

>> python3 -V >> bash: /usr/bin/python3: No such file or directory

>> sudo apt-get install python3 >> Reading package lists... Done Building dependency tree Reading state information... Done The following packages were automatically installed and are no longer required: gir1.2-glib-2.0 libexpat1-dev libgirepository-1.0-1 libpython3-dev libpython3.5-dev python-pip-whl python-pycurl python3.5-dev Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: dh-python Suggested packages: python3-doc python3-tk python3-venv The following NEW packages will be installed: dh-python python3 0 upgraded, 2 newly installed, 0 to remove and 61 not upgraded. Need to get 0 B/82.7 kB of archives. After this operation, 436 kB of additional disk space will be used. Do you want to continue? [Y/n] y Selecting previously unselected package dh-python. (Reading database ... 180938 files and directories currently installed.) Preparing to unpack .../dh-python_2.20151103ubuntu1.2_all.deb ... Unpacking dh-python (2.20151103ubuntu1.2) ... Selecting previously unselected package python3. Preparing to unpack .../python3_3.5.1-3_amd64.deb ... Unpacking python3 (3.5.1-3) ... Processing triggers for man-db (2.7.5-1) ... Setting up python3 (3.5.1-3) ... running python rtupdate hooks for python3.5... /usr/share/python3/runtime.d/dh-python.rtupdate: 5: /usr/share/python3/runtime.d/dh-python.rtupdate: py3clean: not found error running python rtupdate hook dh-python dpkg: error processing package python3 (--configure): subprocess installed post-installation script returned error exit status 4 dpkg: dependency problems prevent configuration of dh-python: dh-python depends on python3:any (>= 3.3.2-2~); however: Package python3 is not configured yet.

dpkg: error processing package dh-python (--configure): dependency problems - leaving unconfigured Errors were encountered while processing: python3 dh-python E: Sub-process /usr/bin/dpkg returned an error code (1)

>> whereis python3 >> python3: /usr/bin/python3.6m /usr/bin/python3.6 /usr/bin/python3.5m /usr/bin/python3 /usr/lib/python3.5 /usr/lib/python3.6 /usr/lib/python3 /etc/python3.5 /etc/python3.6 /etc/python3 /usr/local/lib/python3.5 /usr/local/lib/python3.6 /usr/share/python3 /usr/share/man/man1/python3.1.gz

Please suggest a solution.

Pizza
  • 1,428
user15529314
  • 49
  • 1
  • 1
  • 2

1 Answers1

0

If you want to be sure a package is completely removed, use the "purge" option. This will also remove all configuration files.

sudo apt purge python3
sudo apt-get purge python3

You can also use "*" but this will remove really everything which begins with python3.

sudo apt purge python3*

But as mentioned in many comments removing the system Python is a bad idea. Therefore to have better control over removing check what is still installed.

dpkg -l | grep -E '*python*' | less

Alternatively, you can look directly in the installation directory.

ls /usr/bin/python

This way you can check what python packages you have installed. And see their exact name should you want to remove them.

It appears to me that when you run:

sudo apt-get install python3

it tries to install just the "dh-python" package because it still finds some python package installed. It also tells you that python3 is not configured yet. So it seems it is installed but due to your previous attempts to remove it the configuration is not OK and therefore it can not install "dh-python". So properly removing the python3 package with its configuration files (which was before installed by you, not by the system), should allow you to install it correctly...

EDIT

Before removing Python rather try:

sudo dpkg-reconfigure python3*

In your case, it will be:

sudo dpkg-reconfigure python3.5*

And if you decide to remove python. (The version installed by you, not by system) make sure you check what depends on it. Here you can see how.

  • 1
    Are you sure I should purge python3? I tried this and it made even more of a mess... – Yan King Yin Nov 02 '22 at 10:59
  • 1
    apt purge itself calls dpkg and dpkg says python3 is broken and too many errors. This does not fix anything... – Yan King Yin Nov 02 '22 at 11:19
  • 1
    The purge itself failed with dpkg complaining too many errors. Then I found that one version of python3 (3.6) is still working. So I created sym link via sudo ln -sf /usr/bin/python3.6 /usr/bin/python3 and got back a functioning python. Then I reinstalled via sudo apt install --reinstall python3 python python3-minimal --fix-broken. Now it seems normal again... it really was like going through hell >_< – Yan King Yin Nov 02 '22 at 11:40
  • 1
    @YanKingYin Hell is right, this is a complete nightmare. I've been chasing my tail for hours on this one and it looks like I'm heading for my 7th all nighter in a row on this. How in the world did you figure out which version of python you had that is still working? What if none works? – John Smith Nov 09 '23 at 07:14