title: pip 10 and apt: how to avoid "Cannot uninstall X" errors for distutils packages
body: <p>I am dealing with a legacy Dockerfile. Here is a <em>very simplified</em> version of what I am dealing with:</p>
  <pre><code>FROM ubuntu:14.04
  
  RUN apt-get -y update &amp;&amp; apt-get -y install \
      python-pip \
      python-numpy # ...and many other packages
  
  RUN pip install -U pip
  
  RUN pip install -r /tmp/requirements1.txt # includes e.g., numpy==1.13.0
  RUN pip install -r /tmp/requirements2.txt
  RUN pip install -r /tmp/requirements3.txt
  </code></pre>
  <p>First, several packages are installed using <code>apt</code>, and then several packages are installed using <code>pip</code>. <code>pip</code> version 10 has been released, and <a href="https://pip.pypa.io/en/stable/news/#deprecations-and-removals" rel="noreferrer">part of the release</a> is this new restriction:</p>
  <blockquote>
  <p>Removed support for uninstalling projects which have been installed using distutils. distutils installed projects do not include metadata indicating what files belong to that install and thus it is impossible to actually uninstall them rather than just remove the metadata saying they've been installed while leaving all of the actual files behind.</p>
  </blockquote>
  <p>This leads to the following problem in my setup. For example, first <code>apt</code> installs <code>python-numpy</code>. Later <code>pip</code> tries to install a newer version of <code>numpy</code> from e.g., <code>/tmp/requirements1.txt</code>, and tries to uninstall the older version, but because of the new restriction, it cannot remove this version:</p>
  <pre><code>Installing collected packages: numpy
    Found existing installation: numpy 1.8.2
  Cannot uninstall 'numpy'. 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.
  </code></pre>
  <p>Now I know at this point there are several solutions.</p>
  <p>I could not install <code>python-numpy</code> through <code>apt</code>. However, this causes issues because <code>python-numpy</code> installs a few different packages as requirements, and I do not know if another part of the system relies on these packages. And in reality, there are several <code>apt</code> packages installed through the Dockerfile, and each one I remove seems to reveal another <code>Cannot uninstall X</code> error, and removes a number of other packages along with it, that our app may or may not rely on.</p>
  <p>I could also use the <code>--ignore-installed</code> option when I try to <code>pip</code> install things that have already been installed through <code>apt</code>, but then again I have the same problem of every <code>--ignore-installed</code> argument revealing yet another thing that needs to be ignored.</p>
  <p>I could pin <code>pip</code> at an older version that does not have this restriction, but I don't want to be stuck using an outdated version of <code>pip</code> forever.</p>
  <p>I have been going around in circles trying to come up with a good solution that involves minimal changes to this legacy Dockerfile, and allows the app we deploy with that file to continue to function as it has been. Any suggestions as to how I can safely get around this problem of <code>pip</code> 10 not being able to install newer versions of <code>distutils</code> packages? Thank you!</p>
  <h1>UPDATE:</h1>
  <p>I did not realize that <code>--ignore-installed</code> could be used without a package as an argument to ignore all installed packages. I am considering whether or not this might be a good option for me, and have asked about it <a href="https://stackoverflow.com/q/49932926/3642398">here</a>.</p>