使用pip升级包而不升级依赖项? [英] Upgrade package without upgrading dependencies using pip?

查看:57
本文介绍了使用pip升级包而不升级依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的 Python 应用程序使用 pip 和 virtualenv.我想在不涉及依赖项的情况下升级到应用程序的新版本.当我使用 pip install -U 时,它会尝试升级所有包,甚至在没有新版本可用时卸载并重新安装相同版本的依赖包.

I'm using pip and virtualenv for my python application. I would like to upgrade to a new version of the application without touching the dependencies. When I use pip install -U, it tries to upgrade all the packages, and even uninstalls and re-installs the same version of a dependency package when there isn't a new version available.

我也尝试过 pip install -U --no-deps 但这似乎相当于常规安装而不是升级.是否有标志组合可以满足我的要求?

I also tried pip install -U --no-deps but that seems equivalent to a regular install instead of an upgrade. Is there a combination of flags that will do what I want?

推荐答案

概述:

  • 安装新包而不升级已安装的包:pip install(不带-U)
  • 仅根据要求升级过时的软件包:pip install --upgrade --upgrade-strategy only-if-needed(新版本默认)
  • 将包和所有依赖项升级到最新版本:pip install --upgrade --upgrade-strategy early(旧版本默认)
  • 在不涉及依赖项的情况下安装或升级列出的软件包:--no-deps
  • Install new packages without upgrading installed ones: pip install (without -U)
  • Upgrade only packages that are outdated according to requirements: pip install --upgrade --upgrade-strategy only-if-needed (default in new versions)
  • Upgrade package and all dependencies to latest version: pip install --upgrade --upgrade-strategy eager (default in old versions)
  • Install or upgrade listed packages without touching dependencies: --no-deps

UPDATE(感谢@Jether 的评论):如果您使用的是最新版本的 pip,那么仅在必要时更新依赖项现在是默认行为,您不需要这样做有什么特别的!下面的答案概述了旧版本 pip 的步骤(如果您想便携,它也适用于新版本).

UPDATE (thanks to @Jether's comment): If you're using the latest version of pip, then updating dependencies only when necessary is now the default behavior, and you don't need to do anything special! The answer below outlines the steps for older versions of pip (which also works for newer versions if you want to be portable).

如果你真的不想碰依赖,那么确实要走的路是

If you really want to not touch dependencies, then indeed the way to go is

pip install -U --no-deps mypackage

但我认为你通常想要的是不要升级依赖项,除非它是必需的.在这种情况下,您可以使用:

But I think what you'll usually want is to not upgrade dependencies unless it's required. In that case you can use:

pip install --upgrade --upgrade-strategy only-if-needed mypackage

这仅在软件包需要比安装版本更新的版本时更新要求.

This only updates requirements if the package requires a newer version than is installed.

这篇关于使用pip升级包而不升级依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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