0

I have made a big mess of my python installation, I would like to remove all the versions and do a clean install. How can I do that?

If I try the suggested:

sudo apt-get remove python2.7 --purge

I get:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  fontconfig iso-codes libaudio2 libdatrie1 libgstreamer-plugins-base0.10-0
  libgstreamer0.10-0 libmng1 libmysqlclient18 libqt4-dbus libqt4-declarative
  libqt4-designer libqt4-help libqt4-network libqt4-script libqt4-scripttools
  libqt4-sql libqt4-sql-mysql libqt4-svg libqt4-test libqt4-xml
  libqt4-xmlpatterns libqtassistantclient4 libqtcore4 libqtdbus4 libqtgui4
  libqtwebkit4 libthai-data libthai0 libxrender1 libxt6 mysql-common qdbus
Use 'apt-get autoremove' to remove them.
The following packages will be REMOVED:
  libpython2.7* python* python-bs4* python-chardet* python-cheetah*
  python-imaging* python-lxml* python-mako* python-markupsafe* python-numpy*
  python-openssl* python-picamera* python-pifacecommon*
  python-pifacedigitalio* python-pip* python-pkg-resources* python-qt4*
  python-rpi.gpio* python-serial* python-setuptools* python-sip*
  python-support* python2.7*
0 upgraded, 0 newly installed, 23 to remove and 0 not upgraded.
24 not fully installed or removed.
After this operation, 55.3 MB disk space will be freed.
Do you want to continue [Y/n]? Y
(Reading database ... 44069 files and directories currently installed.)
Removing python-qt4 ...
Segmentation fault
dpkg: error processing python-qt4 (--purge):
 subprocess installed pre-removal script returned error exit status 139
Segmentation fault
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 139
Removing libpython2.7 ...
Purging configuration files for libpython2.7 ...
Removing python-rpi.gpio ...
Segmentation fault
dpkg: error processing python-rpi.gpio (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-pifacedigitalio ...
Segmentation fault
dpkg: error processing python-pifacedigitalio (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-pifacecommon ...
Segmentation fault
dpkg: error processing python-pifacecommon (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-picamera ...
Segmentation fault
dpkg: error processing python-picamera (--purge):
 subprocess installed pre-removal script returned error exit status 139
dpkg: error processing python-openssl (--purge):
 Package is in a very bad inconsistent state - you should
 reinstall it before attempting a removal.
Removing python-numpy ...
Segmentation fault
dpkg: error processing python-numpy (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-support ...
Purging configuration files for python-support ...
Removing python-sip ...
Segmentation fault
dpkg: error processing python-sip (--purge):
 subprocess installed pre-removal script returned error exit status 139
dpkg: error processing python-pip (--purge):
 Package is in a very bad inconsistent state - you should
 reinstall it before attempting a removal.
Removing python-setuptools ...
Segmentation fault
dpkg: error processing python-setuptools (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-serial ...
Segmentation fault
dpkg: error processing python-serial (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-pkg-resources ...
Segmentation fault
dpkg: error processing python-pkg-resources (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-mako ...
Segmentation fault
dpkg: error processing python-mako (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-markupsafe ...
Segmentation fault
dpkg: error processing python-markupsafe (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-lxml ...
Segmentation fault
dpkg: error processing python-lxml (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-imaging ...
Segmentation fault
dpkg: error processing python-imaging (--purge):
 subprocess installed pre-removal script returned error exit status 139
dpkg: error processing python-cheetah (--purge):
 Package is in a very bad inconsistent state - you should
 reinstall it before attempting a removal.
Removing python-chardet ...
Segmentation fault
dpkg: error processing python-chardet (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python-bs4 ...
Segmentation fault
dpkg: error processing python-bs4 (--purge):
 subprocess installed pre-removal script returned error exit status 139
Removing python ...
Purging configuration files for python ...
Removing python2.7 ...
Purging configuration files for python2.7 ...
Processing triggers for man-db ...
Processing triggers for menu ...
Processing triggers for desktop-file-utils ...
Errors were encountered while processing:
 python-qt4
 python-rpi.gpio
 python-pifacedigitalio
 python-pifacecommon
 python-picamera
 python-openssl
 python-numpy
 python-sip
 python-pip
 python-setuptools
 python-serial
 python-pkg-resources
 python-mako
 python-markupsafe
 python-lxml
 python-imaging
 python-cheetah
 python-chardet
 python-bs4
E: Sub-process /usr/bin/dpkg returned an error code (1)
2
  • The easiest way is to just reimage your SD card with a fresh Raspbian install .....
    – Phil B.
    Commented Oct 24, 2015 at 2:14
  • Yes, but that way i will lose all the installation and configurations made along the time. I was trying to avoid that.
    – Agomes
    Commented Oct 24, 2015 at 15:51

3 Answers 3

3

I would add to the answer that one should as well do

sudo apt autoremove

right after the mentioned

sudo apt-get remove python2.7 --purge

this helps to remove packages like python2.7-minimal, which was still providing the python2.7 binary.

Without this I could do the following:

python --version Python 2.7.13

After the autoremove the expected

python --version bash: /usr/bin/python: No such file or directory

is finally there

1
  • Advice to do something after the failed step doesn't help if that step fails.
    – RalfFriedl
    Commented May 4, 2019 at 6:06
3

If you have installed any packages via pip, then you will first have to remove all of those by entering the following command:
sudo pip freeze | grep -v "^-e" | xargs pip uninstall -y

Then, to remove Python and all of its config files:
sudo apt-get remove python2.7 --purge

To reinstall it:
sudo apt-get install python2.7

1
  • debconf will not allow me to remove python2.7 Suggestions? Commented Oct 20, 2017 at 16:17
1

!ATTENTION!

Do not uninstall the default Python. I feel this will help people avoid this mistake in the future.

I followed the recommended answers here and they do work BUT if you remove the default python version you will most likely have an unusable operating system.

Many Linux distributions use the default python for various applications, one of them fore example is the OpenBox app which displays the desktop windows and that will probably crash. You might get a black screen and who knows what other problems see these discussions: how to destroy your pi.....remove Python! and Removed Python 3 on 18.04, how can I fix my system?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.