使用pip升级包而不升级依赖项?
我在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
概述:
pip install
(不带-U
)pip install --upgrade - -upgrade-strategy only-if-needed
(新版本中默认)pip install --upgrade --upgrade-strategy eager
(旧版本中默认版本)UPDATE (感谢 @Jether 的评论):如果您使用的是最新版本的 pip,则仅在必要时更新依赖项现在是默认行为,您无需执行任何特殊操作!下面的答案概述了旧版本 pip 的步骤(如果您想便携,它也适用于新版本)。
如果您真的不想触及依赖项,那么确实要走的路是
但我认为您通常想要的是除非需要,否则不要升级依赖项。在这种情况下,您可以使用:
仅当软件包需要比安装的版本更新的版本时,才会更新要求。
Overview:
pip install
(without-U
)pip install --upgrade --upgrade-strategy only-if-needed
(default in new versions)pip install --upgrade --upgrade-strategy eager
(default in old versions)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
But I think what you'll usually want is to not upgrade dependencies unless it's required. In that case you can use:
This only updates requirements if the package requires a newer version than is installed.
我刚刚尝试了我的 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?你说得对。我认为当我添加
--no-deps
时,它忽略了卸载现有版本。但我又试了一下,发现没有问题: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: