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)
  • The easiest way is to just reimage your SD card with a fresh Raspbian install ..... – Phil B. Oct 24 '15 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 Oct 24 '15 at 15:51
1

If you have installed any packages via pip then you will first have to remove all of those by entering the command:

sudo pip freeze | grep -v "^-e" | xargs pip uninstall -y

Then, to remove python, and all of it's config files:

sudo apt-get remove python2.7 --purge

to reinstall it:

sudo apt-get install python2.7

  • debconf will not allow me to remove python2.7 Suggestions? – Bruno Bronosky Oct 20 '17 at 16:17
0

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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