简体   繁体   English

python包的版本管理

[英]Versions management of python packages

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.我知道 virtualenv,但我不确定它是否适合我的情况。

My problem:我的问题:

Consider that i have 2 projects (P1, P2) which both use 1 small project (P3).考虑到我有 2 个项目(P1、P2),它们都使用了 1 个小项目(P3)。 I use git submodules and add P3 to both P1 and P2.我使用 git 子模块并将 P3 添加到 P1 和 P2。

Then i have P4 which uses all projects described above and P4 needs the latest version of P3.然后我有使用上述所有项目的 P4,而 P4 需要最新版本的 P3。

How to deal with it?如何处理? I want P1, P2, P4 to use their own version of P3.我想让 P1、P2、P4 使用他们自己的 P3 版本。 But when i build P4 i have only one version of P3.但是当我构建 P4 时,我只有一个版本的 P3。

Projects structure:项目结构:

All projects have such structure (some files omitted):所有项目都有这样的结构(省略了一些文件):

P4 example: P4示例:

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

How subprojects are imported:如何导入子项目:

No surprises here, all projects import P3 in that way as it was the only one version installed.毫不奇怪,所有项目都以这种方式导入P3 ,因为它是唯一安装的一个版本。

So P1 uses: from P3 import something所以P1使用: from P3 import something

And P4 also uses: P4 还使用:

from P3 import something

from P1 import something_else

The general rule is that running multiple versions of the same project within a single Python environment is not supported.一般规则是不支持在单个 Python 环境中运行同一项目的多个版本。 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.根据我从这个特定问题中收集到的信息,我相信vendoring可能是一种合适的技术来规避此限制,同时尽可能少地对项目的当前状态进行修改。

1. with git submodules 1. 使用 git 子模块

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

2. with the vendoring tool 2.使用vendoring工具


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.我知道 virtualenv,但我不确定它是否适合我的情况。

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.所以你不能同时从同一个库的两个不同版本导入一个项目。

Virtualenv 会起作用,为什么您认为它不起作用?

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

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