Uninstall Python Built from Source

Uninstall python built from source?

You can use checkinstall to remove Python. The idea is:

  1. Install checkinstall
  2. Use
    checkinstall to make a deb of your
    Python installation
  3. Use dpkg -r to
    remove the deb.

See this post for more details.

PS. Note that Ubuntu must always have at least one installation of Python installed, or else major pieces of your OS stop working. Above, I'm assuming it's safe to remove the Python built from source, without removing the Python that was installed by the package manager.

PPS. If you accidentally erase all Python installations from your Ubuntu machine, all is not lost. Instructions on how to recover from this situation can be found here.

How do I replace a Python installed from source with a packaged version?

Since you opened a bounty, I can't vote to close as a duplicate, but this question would seem to provide a possible solution. Quoting from the accepted answer:

You can use checkinstall to remove Python. The idea is:

  1. Install checkinstall
  2. Use
    checkinstall to make a deb of your
    Python installation
  3. Use dpkg -r to
    remove the deb.

checkinstall basically wraps a make install command and creates a Debian .deb package based on what was installed. Then, you can just uninstall that package to reverse make install completely. To be perfectly safe you may want to uninstall the packaged Python 3.7 first and reinstall it afterwards to avoid any conflicts (I wouldn't expect any, though, since the packaged version lives in /usr while your source version lives in /usr/local).

If you don't have your source files around anymore, you can always download them again (https://www.python.org/downloads/release/python-370b3/) and rebuild Python. Specifically, the checkinstall commands would look something like this:

sudo apt install checkinstall
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0b3.tgz
tar xf Python-3.7.0b3.tgz
cd Python-3.7.0b3
./configure && make
sudo checkinstall -D --fstrans=no make install
sudo dpkg -r Python-3.7.0b3.deb

(-D creates a Debian package, --fstrans=no disables use of a temporary directory for installation).

Uninstalling PIL built from source

Working from Ubuntu 14.04, but this should be generally applicable. When I installed, I called the following:

sudo python setup.py install

I noted the following statements describing the default installation:

...
Installing pildriver.py script to /usr/local/bin
Installing viewer.py script to /usr/local/bin
Installing gifmaker.py script to /usr/local/bin
Installing painter.py script to /usr/local/bin
Installing pilfont.py script to /usr/local/bin
Installing pilprint.py script to /usr/local/bin
Installing pilconvert.py script to /usr/local/bin
Installing enhancer.py script to /usr/local/bin
Installing pilfile.py script to /usr/local/bin
Installing createfontdatachunk.py script to /usr/local/bin
Installing explode.py script to /usr/local/bin
Installing thresholder.py script to /usr/local/bin
Installing player.py script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/Pillow-3.4.2-py2.7-linux-x86_64.egg

So, I ran the following:

cd /usr/local/bin
sudo rm -f pildriver.py viewer.py gifmaker.py painter.py pilfont.py pilprint.py pilconvert.py enhancer.py pilfile.py createfontdatachunk.py explode.py thresholder.py player.py
sudo rm -f /usr/local/lib/python2.7/dist-packages/Pillow-3.4.2-py2.7-linux-x86_64.egg

After reinstalling Pillow (python-imaging) through apt-get, everything's running fine.

How to remove python in /usr/local/bin/

DISCLAIMER: I've since learned a lot, and would recommend setting environment variables for a shell or shell session rather than use this answer. For example, if you manually relink the system's Python2 interpreter to a Python3 interpreter, you may wreak havoc on your system. Please use this answer with caution.

Just reset the symlink.

First, find out which python:

$ which python

In my case, I get:

/usr/local/bin/python

Then find where the symlink points to

$ file /usr/local/bin/python
/usr/local/bin/python: symbolic link to `/usr/bin/python'

Then just repoint the symlink back to the default (in this case, I use the default: /usr/bin/python).

No uninstalls necessary.

Update


I've since found a lot of better ways to enact this exact same behavior, without having effects on the entire system.

Say I have an undesired python install in /usr/bin, and a desired python install in /opt/bin. Let's say for the point of comparison that the /usr/bin is Python 3.5, and the /opt/bin is Python 2.7. This would create immediate consequences for using the wrong Python interpreter, rather than subtle errors down the line.

Application Defaults

If you would like to (on Linux systems) change which interpeter runs Python scripts, you can change this either via a GUI, or via xdg-mime (a walkthrough can be found here). For macOS or Windows, this can be done easily through a GUI.

Interactive Shell

If you would like to change the default Python for a specific shell, I can see two good ways of doing this. One would be to change the default search PATH to set /opt/bin before usr/bin for a specific situation, however, if you have numerous alternative installs to system packages, this might pose issues too. Another would be to set an alias for Python to the version you want to use. This is the preferred solution, as it only changes the interpreter and is merely a shortcut to reference an existing command.

For example, to set the alias I could use:

alias python="/opt/bin/python"

And to change the default path, I could use:

export PATH=/opt/bin:$PATH

Adding these lines to ~/.bashrc or ~/.bash_aliases (the latter is Ubuntu-only by default) will make these shortcuts be the default on any interactive shell you start. Combining application defaults and interactive shell scripting allows you to have tight control over which interpreter runs your code, but does not require interfering with potentially crucial system files.

How do you cleanly remove Python when it was installed with 'make altinstall'?

As far as I know, there’s no automatic way to do this. But you can go into /usr/local and delete bin/pythonX and lib/pythonX (and maybe lib64/pythonX).

But more generally, why bother? The whole point of altinstall is that many versions can live together. So you don't need to delete them.

For your tests, what you should do is use virtualenv to create a new, clean environment, with whichever python version you want to use. That lets you keep all your altinstalled Python versions and still have a clean environment for tests.

Also, do the same (use virtualenv) for development. Then your altinstall’ed Pytons don't have site packages. They just stay as clean, pristine references.

Removing second python install

If you installed it from source, apt-install has no idea that it exists.

The easiest way (as most makefiles don't have an uninstall target) is to run make install again in your 3.3.2 source directory and capture what it sticks where and then remove them.

The cheaper way would be to rm /usr/local/bin/python3 and probably anything else in /usr/local/bin/py* including symlinks to various parts of the suite.

How do you uninstall a python package that was installed using distutils?

It varies based on the options that you pass to install and the contents of the distutils configuration files on the system/in the package. I don't believe that any files are modified outside of directories specified in these ways.

Notably, distutils does not have an uninstall command at this time.

It's also noteworthy that deleting a package/egg can cause dependency issues – utilities like easy_install attempt to alleviate such problems.



Related Topics



Leave a reply



Submit