python软件包的版本管理 [英] Versions management of python packages

查看:155
本文介绍了python软件包的版本管理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

管理不同版本的软件包的最佳实践是什么? 我了解virtualenv,但是我不确定它是否适合我的情况.

What is a best practice to manage a different versions of packages? I know about virtualenv but i am not sure it is suitable in my case.

考虑我有2个项目(P1,P2),它们都使用1个小项目(P3). 我使用git子模块,并将P3添加到P1和P2.

Consider that i have 2 projects (P1, P2) which both use 1 small project (P3). I use git submodules and add P3 to both P1 and P2.

然后我有使用上述所有项目的P4,P4需要P3的最新版本.

Then i have P4 which uses all projects described above and P4 needs the latest version of P3.

如何处理? 我希望P1,P2,P4使用自己的P3版本.但是当我构建P4时,我只有P3的一个版本.

How to deal with it? I want P1, P2, P4 to use their own version of P3. But when i build P4 i have only one version of P3.

所有项目都具有这种结构(省略了一些文件):

All projects have such structure (some files omitted):

P4 示例:

├── project_name (sources are here)
├── Makefile
├── submodules
│   └── P1
│       ├── submodules
│       │   └── P3
│   └── P2
│       ├── submodules
│       │   └── P3
│   └── P3
├── tests
└── setup.py

子项目的导入方式:

在这里不足为奇,所有项目都以这种方式导入 P3 ,因为它是唯一安装的一个版本.

How subprojects are imported:

No surprises here, all projects import P3 in that way as it was the only one version installed.

因此 P1 使用: from P3 import something

P4还使用:

from P3 import something

from P1 import something_else

推荐答案

一般规则是,不支持在单个Python环境中运行同一项目的多个版本.显然(就像软件中的其他限制一样),有很多方法可以解决,但是它们都需要大量的工作.

The general rule is that running multiple versions of the same project within a single Python environment is not supported. Obviously (like any other kind of limitation in software) there are ways to go around it, but they all require quite a bit of work.

根据我对这个特定问题的了解,我相信供应商可能是一种规避此限制的合适技术,同时需要对项目的当前状态进行尽可能少的修改.

From what I can gather from this particular question, I believe vendoring could be a fitting technique to circumvent this limitation while requiring as little modifications as possible to the current state of the project.

1.带有git子模块

  • P3 保留在另一个 git 存储库中.
  • 使用 git子模块在主项目中具有两个不同的 P3 副本.
  • Keep P3 in a different git repository.
  • Use git submodules to have two different copies of P3 in the main project.

2.使用供应商工具

  • Promote P3 to its own Python project with complete packaging.
  • Use the vendoring tool to have two different copies of P3 in the main project. See for example how pip uses it in "Switch to a dedicated tool for vendoring pip's dependencies #7485"

管理不同版本的软件包的最佳实践是什么?我了解virtualenv,但是我不确定它是否适合我的情况.

What is a best practice to manage a different versions of packages? I know about virtualenv but i am not sure it is suitable in my case.

不是.虚拟环境可以帮助例如使用同一库的两个不同版本在两个不同的项目上工作.但是,这两个项目将需要生活在两个不同的虚拟环境中.因此,您不可能有一个项目同时从同一库的两个不同版本中导入.

It is not. Virtual environments could help for example to work on two different projects using two different versions of the same library. But the two projects would need to live in two different virtual environments. So you couldn't have one single project importing simultaneously from two different versions of a same library.

这篇关于python软件包的版本管理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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