Pip Cannot Uninstall <Package>: "It Is a Distutils Installed Project"

pip cannot uninstall package: It is a distutils installed project

This error means that this package's metadata doesn't include a list of files that belong to it. Most probably, you have installed this package via your OS' package manager, so you need to use that rather than pip to update or remove it, too.

See e.g. Upgrading to pip 10: It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall. · Issue #5247 · pypa/pip for one such example where the package was installed with apt.


Alternatively, depending on your needs, it may be more productive to not use your system Python and/or its global environment but create a private Python installation and/or environment. There are many options here including virtualenv, venv, pyenv, pipenv and installing Python from source into
/usr/local or $HOME/$HOME/.local (or /opt/<whatever>).


Finally, I must comment on the often-suggested (e.g. at pip 10 and apt: how to avoid "Cannot uninstall X" errors for distutils packages) --ignore-installed pip switch.

It may work (potentially for a long enough time for your business needs), but may just as well break things on the system in unpredictable ways. One thing is sure: it makes the system's configuration unsupported and thus unmaintainable -- because you have essentially overwritten files from your distribution with some other arbitrary stuff. E.g.:

  • If the new files are binary incompatible with the old ones, other software from the distribution built to link against the originals will segfault or otherwise malfunction.
  • If the new version has a different set of files, you'll end up with a mix of old and new files which may break dependent software as well as the package itself.
  • If you change the package with your OS' package manager later, it will overwrite pip-installed files, with similarly unpredictable results.
  • If there are things like configuration files, differences in them between the versions can also lead to all sorts of breakage.

PIP: Cannot uninstall 'ipython'. It is a distutils installed project and thus we cannot accurately determine...

Just solved with:

sudo apt-get remove ipython

Uninstall a distutils installed project on windows?

It turns out that anything installed using an installer executable is officially stored as a program, even if it was a single python package. In this case the originally installed pywin32-219 package could be uninstalled by the system through Control Panel -> Uninstall a Program. Then the new package could be installed using pip and the problem was fixed.

SQL Server 2017 MLS and pip - cannot uninstall package: “It is a distutils installed project”

When SQL 2017 MLS does the initial installation, it functions as the package manager. So when Pip comes along and tries to update the distutil packages, the packages dont recognize Pip as having authority to update the packages.

This also effectively means that MLS has a hard limitation with any packages that are "distutils locked" and these specific packages are 100% non-updatable. This may affect your application if it needs to update these packages.

Possibly this means a separate non-MS python stack that can be 100% updated would be the go if you need to update any package as required.

pip 10 and apt: how to avoid Cannot uninstall X errors for distutils packages

This is the solution I ended up going with, and our apps have been running in production without any issues for close to a month with this fix in place:

All I had to do was to add

--ignore-installed

to the pip install lines in my dockerfile that were raising errors. Using the same dockerfile example from my original question, the fixed dockerfile would look something like:

FROM ubuntu:14.04

RUN apt-get -y update && apt-get -y install \
python-pip \
python-numpy # ...and many other packages

RUN pip install -U pip

RUN pip install -r /tmp/requirements1.txt --ignore-installed # don't try to uninstall existing packages, e.g., numpy
RUN pip install -r /tmp/requirements2.txt
RUN pip install -r /tmp/requirements3.txt

The documentation I could find for --ignore-installed was unclear in my opinion (pip install --help simply says "Ignore the installed packages (reinstalling instead)."), and I asked about the potential dangers of this flag here, but have yet to get satisfying answer. However, if there are any negative side effects, our production environment has yet to see the effects of them, and I think the risk is low/none (at least that has been our experience). I was able to confirm that in our case, when this flag was used, the existing installation was not uninstalled, but that the newer installation was always used.

Update:

I wanted to highlight this answer by @ivan_pozdeev. He provides some information that this answer does not include, and he also outlines some potential side-effects of my solution.

Python pip install fails: invalid command egg_info

Install distribute, which comes with egg_info.

Should be as simple as pip install Distribute.

Distribute has been merged into Setuptools as of version 0.7. If you are using a version <=0.6, upgrade using pip install --upgrade setuptools or easy_install -U setuptools.

Error Import Error: No module named numpy on Windows

Support for Python 3 was added in NumPy version 1.5.0, so to begin with, you must download/install a newer version of NumPy.

Or simply using pip:

python3 -m pip install numpy


Related Topics



Leave a reply



Submit