具有冲突依赖项的 Python 包

问题描述

我们正在尝试安装几个自己编写的 python3 应用程序,它们共享一些版本冲突的库.

we are trying to install several own written python3 applications sharing some libraries with conflicting versions.

我们目前正在讨论在 PYTHONPATH 和/或 pythons virtualenv 中使用包的顺序.

We are currently discussing employing the order of packages inside the PYTHONPATH and/ or pythons virtualenv.

你会怎么处理?


解决方案

你可以使用pipx.

pipx 将为每个应用程序设置单独的虚拟环境,以便所有应用程序的依赖项保持独立.

pipx will do all the work of setting up separate virtual environments for each application, so that all the applications' dependencies remain separate.

如果您自己使用 virtualenv,则必须切换环境以运行不同的应用程序.pipx 为您处理环境,因此您根本不必弄乱 virtualenvs.

If you use virtualenv yourself, you have to switch environments to run a different application. pipx handles the environment for you, so you don't have to mess with the virtualenvs at all.

来自文档:

pipx 专为应用程序安装而设计,因为它增加了隔离性,但仍使应用程序在您的 shell 中可用:pipx 为每个应用程序及其关联的包创建一个隔离的环境.

pipx is made specifically for application installation, as it adds isolation yet still makes the apps available in your shell: pipx creates an isolated environment for each application and its associated packages.

旧答案(pipsi 不再维护,但 pipx 的用法几乎相同)

您可以使用 pipsi.

pipsi 将为每个应用程序设置单独的虚拟环境,以便所有应用程序的依赖项保持独立.

pipsi will do all the work of setting up separate virtual environments for each application, so that all the applications' dependencies remain separate.

如果您自己使用 virtualenv,则必须切换环境以运行不同的应用程序.pipsi 为您处理环境,因此您根本不必弄乱 virtualenvs.

If you use virtualenv yourself, you have to switch environments to run a different application. pipsi handles the environment for you, so you don't have to mess with the virtualenvs at all.

来自文档:

如果您要全局安装 Python 包以进行 cli 访问,您几乎可以肯定要使用 pipsi 而不是运行 sudo pip .... 所以你得到的

If you are installing Python packages globally for cli access, you almost certainly want to use pipsi instead of running sudo pip .... so that you get

  • 隔离的依赖关系保证没有版本冲突
  • 无需使用 sudo 即可全局安装软件包的能力
  • 能够在不影响的情况下卸载包及其依赖项其他全局安装的 Python 程序

相关文章