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

查看:33
本文介绍了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天全站免登陆