I installed Python 2.7.9 on Ubuntu 14.04 by compiling its source, by .configre, make, and make altinstall. make altinstall is because I don't want to overwrite the default Python 2.7.6. My self installed 2.7.9 is in /usr/local/bin/python2.7 and many other files in other directories under /usr/local. From README in the source installation package:

On Unix and Mac systems if you intend to install multiple versions of Python using the same installation prefix (--prefix argument to the configure script) you must take care that your primary python executable is not overwritten by the installation of a different version.

All files and directories installed using "make altinstall" contain the major and minor version and can thus live side-by-side. "make install" also creates ${prefix}/bin/python which refers to ${prefix}/bin/pythonX.Y.

If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using "make install". Install all other versions using "make altinstall".

For example, if you want to install Python 2.5, 2.6 and 3.0 with 2.6 being the primary version, you would execute "make install" in your 2.6 build directory and "make altinstall" in the others.

Now I want to uninstall my self installed 2.7.9.

  1. Fortunately I still have the source code, but unfortunately, the Makefile doesn't have uninstall section

    $ sudo make uninstall
    make: *** No rule to make target `uninstall'.  Stop.
  2. Then I tried another way: first create a deb from the source and compilation, install the deb (hopefully overwriting the installed files from make altinstall), and then uninstall the deb.

    But when I create the deb file by checkinstall, I am not sure if and how I should do differently for make altinstall from for make install. What I tried is:

    $ checkinstall altinstall
    Installing with altinstall...
    ========================= Installation results ===========================
    /var/tmp/tmp.4ZzIiwqBNL/installscript.sh: 4: /var/tmp/tmp.4ZzIiwqBNL/installscript.sh: altinstall: not found

    I wonder how I can create a deb so that installing the deb will duplicate the installation process of make altinstall?

  3. Or what is your way of uninstalling my python 2.7.9?

Note: the source package in the first link also has setup.py, install-sh besides README.

  • Python doesn't install in so many places. I would just remove the files manually. Mar 17, 2015 at 18:25
  • 1
    thanks.what are those not many places then?
    – Tim
    Mar 17, 2015 at 18:27
  • Take a look at one of the binary packages. It's essentially the same places, I think, except that /usr/local is used instead of /usr. dpkg -L python2.7 and dpkg -L python2.7-minimal. And what do you need 2.7.9 for? Mar 17, 2015 at 18:57
  • I heard that it has pip by default. But after installing, I don't find it has pip.
    – Tim
    Mar 17, 2015 at 19:12
  • You can install pip apt-get install python-pip. Mar 17, 2015 at 19:14

5 Answers 5


The following commands will remove your make altinstall-ed python:

rm -f /usr/local/bin/python2.7
rm -f /usr/local/bin/pip2.7
rm -f /usr/local/bin/pydoc
rm -rf /usr/local/include/python2.7
rm -f /usr/local/lib/libpython2.7.a
rm -rf /usr/local/lib/python2.7

You might also have to do

rm -f /usr/local/share/man/python2.7.1
rm -rf /usr/local/lib/pkgconfig
rm -f /usr/local/bin/idle
rm -f /usr/local/bin/easy_install-2.7

Although make altinstall has served me well if the "system python" has a different major.minor number from the one you install, it doesn't work that well if only the micro number (the third position) differs. That number is excluded from the installed binary, and you end up with two versions pythonX.Y. This was always a problem but once distributions started shipping with system utilities based on 2.7.X this problem has been more severe as 2.7 is supposed to be the last of the Python2 series.

IMO the best approach to solve this problem is to prevent it from becoming one: configure python to install in a directory not used by any other python. On my system they go under /opt/python/X.Y.Z.

To use any of the Pythons installed there you use [virualenv][1] to make a new environment:

virtualenv --python=/opt/python/2.7.9/bin/python2.7 venv
source venv/bin/activate

or use [virtualenvwrapper][2]. I have some aliases for the latest versions in the series I work with.

If you are using tox for testing against multiple versions (you should) the following alias will help it find the various version:

alias tox='PATH=/opt/python/2.7.9/bin:/opt/python/2.6.9/bin:/opt/python/3.4.3/bin:/opt/python/3.3.6/bin:/opt/python/3.5-dev/bin:$PATH tox'

(these are currently the latest versions, I use a slightly different setup by maintaining links from /opt/python/2.7 to the latest /opt/python/2.7.9, and for the other minor numbers as well, within the process for downloading, building and installing a new python version)

These installs are never used directly. They are always used as the basis for virtualenv environments only, hence I don't care that they are not in my normal PATH.

  • 2
    Do not delete /usr/local/lib/python2.7! All global python modules installed by pip live in /usr/local/lib/python2.7/dist-packages. All those modules will break!
    – abhaga
    Oct 6, 2016 at 6:59
  • 4
    @abhaga You should not install with pip outside of a virtualenv on any linux installation
    – Anthon
    Oct 6, 2016 at 7:10
  • We should also not uninstall packages by manually removing files and directories. :) These are good practices and there are always occasions when we need to break them. But it is important to know that it is not safe to remove that directory.
    – abhaga
    Oct 6, 2016 at 7:22
  • In my CentOS7, there are some different: 1. include should be: /usr/local/include/python2.7 , without bin; 2. man file is /usr/local/share/man/man1/python2.7.1 ; 3. Another file: /usr/local/bin/python2.7-config
    – Bin S
    Mar 23, 2018 at 22:34

Starting from @Anthon's rm list, and applying @bin-s advice to search for newer files, i came up with this bash-script to completely wipe-out my Python-3.6.6 (which had been installed from sources with make altinstall):


rm -rf \
    $HOME/.local/lib/Python${pyver} \
    ${prefix}bin/python${pyver} \
    ${prefix}bin/python${pyver}-config \
    ${prefix}bin/pip${pyver} \
    ${prefix}bin/pydoc \
    ${prefix}bin/include/python${pyver} \
    ${prefix}lib/libpython${pyver}.a \
    ${prefix}lib/python${pyver} \
    ${prefix}lib/pkgconfig/python-${pyver}.pc \
    ${prefix}lib/libpython${pyver}m.a \
    ${prefix}bin/python${pyver}m \
    ${prefix}bin/2to3-${pyver} \
    ${prefix}bin/python${pyver}m-config \
    ${prefix}bin/idle${pyver} \
    ${prefix}bin/pydoc${pyver} \
    ${prefix}bin/pyvenv-${pyver} \
    ${prefix}share/man/man1/python${pyver}.1 \
rm -rI ${prefix}bin/pydoc ## WARN: skip if other pythons in local exist.

Use it with care (e.g. add -I option in rm command, to verify each kill).

  • very nice. Now python3.X does not show up when I type python3 and hit tab Oct 8, 2019 at 3:00
  • @ankostis, you may wish to add /$HOME/.local/lib/Python$(pyver) to your list for completeness. This may only be present on later versions of Python.
    – Jonathan
    Jun 16, 2020 at 22:33
  • And these 3 files are not included /usr/local/bin/easy_install-3.7, /usr/local/include/python3.9 and /usr/local/lib/pkgconfig/python-3.9-embed.pc *** First you remove ${prefix}bin/pydoc in the first command and then you give a WARNing:-)
    – Winand
    May 18, 2022 at 11:42

Usually all files are installed in almost one minute. You can use "find" to check all installed files nearly the same time, then "rm" them manually. Wish it helpful.

find /usr/local/ -type f -newer <some latest old file>

I ended up doing following:

  1. rebuild and install Python you want to uninstall using custom prefix, let's say $HOME/opt/Python-3.8.0: tar tJf Python-3.8.0.tar.xz && cd Python-3.8.0 && ./configure --prefix $HOME/opt/Python-3.8.0 && make && make install
  2. cd $HOME/opt/Python-3.8.0 && find * -type f | perl -pe's(^)(/usr/)' | sudo xargs rm
  3. rm -rf ~/opt/Python-3.8.0

Bin S's and Anthon's answers helped me, and I was able to get the uninstall down to 3 lines of Bash:

touch /tmp/marker
sudo make install
sudo rm -rf /usr/local/{include,lib}/python3.13
sudo find /usr/local -newer /tmp/marker -type f -delete
sudo find /usr/local -newer /tmp/marker -type l -delete


find /usr/local/ -newer /tmp/marker

And from now on, I'll try to remember the /opt/python/x.y.z approach for my PREFIX, or maybe /usr/local/pythonx.y.z.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .