使用pip升级包而不升级依赖项?

发布于 2024-09-02 04:58:02 字数 199 浏览 11 评论 0原文

我在 python 应用程序中使用 pip 和 virtualenv。我想升级到应用程序的新版本而不触及依赖项。当我使用 pip install -U 时,它会尝试升级所有包,甚至在没有可用的新版本时卸载并重新安装相同版本的依赖包。

我还尝试了 pip install -U --no-deps 但这似乎相当于常规安装而不是升级。是否有可以实现我想要的功能的标志组合?

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゞ记忆︶ㄣ 2024-09-09 04:58:02

概述:

  • 安装新软件包而不升级已安装的软件包:pip install(不带-U
  • 根据要求仅升级过时的软件包:pip install --upgrade - -upgrade-strategy only-if-needed(新版本中默认)
  • 将包和所有依赖项升级到最新版本:pip install --upgrade --upgrade-strategy eager(旧版本中默认版本)
  • 安装或升级列出的软件包而不触及依赖项: --no-deps

UPDATE (感谢 @Jether 的评论):如果您使用的是最新版本的 pip,则仅在必要时更新依赖项现在是默认行为,您无需执行任何特殊操作!下面的答案概述了旧版本 pip 的步骤(如果您想便携,它也适用于新版本)。

如果您真的不想触及依赖项,那么确实要走的路是

pip install -U --no-deps mypackage

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

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

仅当软件包需要比安装的版本更新的版本时,才会更新要求。

Overview:

  • 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 (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.

何以畏孤独 2024-09-09 04:58:02

我刚刚尝试了我的 virtualenv 项目,pip install -U --no-deps mypackage 似乎工作得很好。它只是下载 mypackage 而没有其他。你的设置是什么样的?

I just tried on my virtualenv project and pip install -U --no-deps mypackage seems to work just fine. It just download mypackage and nothing else. What's your set up like?

甜心小果奶 2024-09-09 04:58:02

你说得对。我认为当我添加 --no-deps 时,它忽略了卸载现有版本。但我又试了一下,发现没有问题:

$ pip install -U --no-deps myproj
Downloading/unpacking myproj
  Downloading myproj-1.0-trunk.31072.tar.gz (43Kb): 43Kb downloaded
  Running setup.py egg_info for package myproj
Installing collected packages: myproj
  Found existing installation: myproj 1.0-trunk.31053
    Uninstalling myproj:
      Successfully uninstalled myproj
  Running setup.py install for myproj
Successfully installed myproj
Cleaning up...

You're right. I thought that when I added --no-deps it had neglected to uninstall the existing version. But I tried it again and see there's no issue:

$ pip install -U --no-deps myproj
Downloading/unpacking myproj
  Downloading myproj-1.0-trunk.31072.tar.gz (43Kb): 43Kb downloaded
  Running setup.py egg_info for package myproj
Installing collected packages: myproj
  Found existing installation: myproj 1.0-trunk.31053
    Uninstalling myproj:
      Successfully uninstalled myproj
  Running setup.py install for myproj
Successfully installed myproj
Cleaning up...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文