12

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. – Faheem Mitha Mar 17 '15 at 18:25
  • thanks.what are those not many places then? – Tim Mar 17 '15 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? – Faheem Mitha Mar 17 '15 at 18:57
  • I heard that it has pip by default. But after installing, I don't find it has pip. – Tim Mar 17 '15 at 19:12
  • You can install pip apt-get install python-pip. – Faheem Mitha Mar 17 '15 at 19:14
15

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/bin/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.

  • This saved my day! Thank you so much! – Paulo Pedroso Nov 24 '15 at 18:42
  • 1
    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 '16 at 6:59
  • 2
    @abhaga You should not install with pip outside of a virtualenv on any linux installation – Anthon Oct 6 '16 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 '16 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 '18 at 22:34
1

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>
1

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):

prefix='/usr/local/'
pyver='3.6'

rm -rf \
    ${prefix}bin/python${pyver} \
    ${prefix}bin/pip${pyver} \
    ${prefix}bin/pydoc \
    ${prefix}bin/include/python${pyver} \
    ${prefix}lib/libpython${pyver}.a \
    ${prefix}lib/python${pyver} \
    ${prefix}bin/python${pyver} \
    ${prefix}bin/pip${pyver} \
    ${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 \
    ${prefix}include/python${pyver}m
    ${prefix}bin/pydoc ## WARN: skip if other pythons in local exist.

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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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