pip 10和apt:如何避免出现“无法卸载X" distutils软件包错误 [英] pip 10 and apt: how to avoid "Cannot uninstall X" errors for distutils packages

查看:213
本文介绍了pip 10和apt:如何避免出现“无法卸载X" distutils软件包错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理旧版Dockerfile.这是我正在处理的非常简化版本:

I am dealing with a legacy Dockerfile. Here is a very simplified version of what I am dealing with:

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 # includes e.g., numpy==1.13.0
RUN pip install -r /tmp/requirements2.txt
RUN pip install -r /tmp/requirements3.txt

首先,使用apt安装多个软件包,然后使用pip安装多个软件包. pip版本10已发布,并且发布的一部分是此新限制吗?

First, several packages are installed using apt, and then several packages are installed using pip. pip version 10 has been released, and part of the release is this new restriction:

不再支持卸载使用distutils安装的项目. distutils安装的项目不包括指示哪些文件属于该安装的元数据,因此无法实际卸载它们,而仅删除表示已安装文件的元数据,而将所有实际文件都留在后面是不可能的.

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.

这在我的设置中导致以下问题.例如,首先apt安装python-numpy.后来pip尝试从例如/tmp/requirements1.txt安装新版本的numpy,并尝试卸载旧版本,但是由于新的限制,它无法删除该版本:

This leads to the following problem in my setup. For example, first apt installs python-numpy. Later pip tries to install a newer version of numpy from e.g., /tmp/requirements1.txt, and tries to uninstall the older version, but because of the new restriction, it cannot remove this version:

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.

现在我知道目前有几种解决方案.

Now I know at this point there are several solutions.

我无法通过apt安装python-numpy.但是,这会引起问题,因为python-numpy根据要求安装了一些不同的软件包,并且我不知道系统的另一部分是否依赖于这些软件包.实际上,通过Dockerfile安装了几个apt软件包,而我删除的每个软件包似乎都揭示了另一个Cannot uninstall X错误,并删除了许多其他软件包,我们的应用程序可能依赖也可能不依赖.

I could not install python-numpy through apt. However, this causes issues because python-numpy 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 apt packages installed through the Dockerfile, and each one I remove seems to reveal another Cannot uninstall X error, and removes a number of other packages along with it, that our app may or may not rely on.

当我尝试pip安装已经通过apt安装的东西时,我也可以使用--ignore-installed选项,但是对于每个--ignore-installed参数,我又遇到了同样的问题,揭示了另一件事:需要被忽略.

I could also use the --ignore-installed option when I try to pip install things that have already been installed through apt, but then again I have the same problem of every --ignore-installed argument revealing yet another thing that needs to be ignored.

我可以将pip固定在没有此限制的较旧版本中,但是我不想永远被过时的pip版本所困扰.

I could pin pip at an older version that does not have this restriction, but I don't want to be stuck using an outdated version of pip forever.

我一直在努力寻找一种好的解决方案,该解决方案只需对该旧Dockerfile进行最小的更改,并允许我们使用该文件部署的应用程序继续按原样运行.关于如何安全地解决pip 10无法安装更新版本的distutils软件包的问题的任何建议?谢谢!

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 pip 10 not being able to install newer versions of distutils packages? Thank you!

我没有意识到--ignore-installed可以在没有软件包的情况下用作忽略所有已安装软件包的参数.我正在考虑这是否对我来说是一个不错的选择,并在此处对此进行了询问.

I did not realize that --ignore-installed 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 here.

推荐答案

这是我最终使用的解决方案,并且使用此修复程序,我们的应用程序已经在生产环境中运行了将近一个月,没有任何问题:

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:

我要做的就是添加

--ignore-installed

到我的dockerfile中出现错误的pip install行.使用与我最初的问题相同的dockerfile示例,固定的dockerfile看起来类似于:

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

我认为我找不到有关--ignore-installed的文档(pip install --help只是说忽略已安装的软件包(改为重新安装)."),我询问该标志此处,但尚未获得令人满意的答案.但是,如果有任何负面影响,我们的生产环境尚未见到它们的影响,我认为风险很小/没有(至少这是我们的经验).我能够确认在我们的情况下,当使用此标志时,不会卸载现有安装,但始终使用较新的安装.

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.

我想突出显示通过@ivan_pozdeev回答.他提供了此答案未包括的一些信息,并且他还概述了我的解决方案的一些潜在副作用.

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.

这篇关于pip 10和apt:如何避免出现“无法卸载X" distutils软件包错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆