简体   繁体   English

从require.txt安装新软件包,而不升级已经满足的依赖关系

[英]Install a new package from requirement.txt without upgrading the dependencies which are already satisfied

I am using requirement.txt to specify the package dependencies that are used in my python application. 我正在使用require.txt来指定我的python应用程序中使用的包依赖关系。 And everything seems to work fine for packages of which either there are no internal dependencies or for the one using the package dependencies which are not already installed. 对于没有内部依赖性的软件包或使用尚未安装的软件包依赖性的软件包,一切似乎都可以正常工作。

The issue occurs when i try to install a package which has a nested dependency on some other package and an older version of this package is already installed. 当我尝试安装对某些其他软件包具有嵌套依赖项的软件包并且已经安装了该软件包的较早版本时,会发生此问题。

I know i can avoid this while installing a package manually bu using pip install -U --no-deps <package_name> . 我知道我可以在使用pip install -U --no-deps <package_name>手动安装软件包时避免这种情况。 I want to understand how to do this using the requirement.txt as the deployment and requirement installation is an automated process. 我想了解如何使用require.txt进行此操作,因为部署和需求安装是一个自动化过程。

Note: 注意:

The already installed package is not something i am directly using in my project but is part of a different project on the same server. 已经安装的软件包不是我在项目中直接使用的软件包,而是同一服务器上不同项目的一部分。

Thanks in advance. 提前致谢。

Dependency resolution is a fairly complicated problem. 依赖性解析是一个相当复杂的问题。 A requirements.txt just specifies your dependencies with optional version ranges. Requirements.txt只是使用可选的版本范围指定了您的依赖项。 If you want to "lock" your transitive dependencies (dependencies of dependencies) in place you would have to produce a requirements.txt that contains exact versions of every package you install with something like pip freeze . 如果要“锁定”传递依赖关系(依赖关系的依赖关系),则必须生成一个requirements.txt,其中包含您安装的每个软件包的确切版本,例如pip freeze This doesn't solve the problem but it would at least point out to you on an install which dependencies conflict so that you can manually pick the right versions. 这不能解决问题,但是至少会在依赖冲突的安装上向您指出,以便您可以手动选择正确的版本。

That being said the new (as of writing) officially supported tool for managing application dependencies is Pipenv . 话虽这么说,用于管理应用程序依赖项的新的(截至撰写本文时)官方支持的工具是Pipenv This tool will both manage the exact versions of transitive dependencies for you (so you won't have to maintain a "requirements.txt" manually) and it will isolate the packages that your code requires from the rest of the system. 此工具将为您管理传递依赖项的确切版本(因此您不必手动维护“ requirements.txt”),并且它将代码所需的包与系统的其余部分隔离开。 (It does this using the virtualenv tool under the hood). (它使用引擎盖下的virtualenv工具执行此操作)。 This isolation should fix your problems with breaking a colocated project since your project can have different versions of libraries than the rest of the system. 这种隔离应该可以解决因断开同一项目而导致的问题,因为您的项目可以具有与系统其余部分不同的库版本。

(TL;DR Try using Pipenv and see if your problem just disappears) (TL; DR尝试使用Pipenv,看看问题是否刚刚消失)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM