安装多个版本的包

安装多个版本的包

本文介绍了使用 pip 安装多个版本的包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想使用:

  • packageA,需要packageX==1.3
  • packageB,需要packageX==1.4
  • packageX==1.5

如何使用 pip 安装多个版本的 packageX 来处理这种情况?

解决方案

pip 不会帮助你解决这个问题.

您可以告诉它安装特定版本,但它会覆盖另一个版本.另一方面,使用两个 virtualenv 会让你在同一台机器上安装两个版本,但不能同时使用它们.

最好的办法是手动安装这两个版本,将它们以不同的名称放在 Python 路径中.

但是如果您的两个库希望它们具有相同的名称(并且它们应该如此),您将不得不修改它们,以便它们使用一些导入别名获取所需的版本,例如:

import dependencyname_version 作为dependencyname

目前没有干净的方法可以做到这一点.您所能希望的最好的方法就是让这个 hack 起作用.

我宁愿放弃两个库中的一个并用等效项替换它,或者对其进行修补以接受新版本的依赖项并将修补程序回馈给社区.

In my application I would like to use:

  • packageA, which requires packageX==1.3
  • packageB, which requires packageX==1.4
  • packageX==1.5

How can I install multiple versions of packageX with pip to handle this situation?

解决方案

pip won't help you with this.

You can tell it to install a specific version, but it will override the other one. On the other hand, using two virtualenvs will let you install both versions on the same machine, but not use them at the same time.

You best bet is to install both version manually, by putting them in your Python path with a different name.

But if your two libs expect them to have the same name (and they should), you will have to modify them so they pick up the version they need with some import alias such as:

import dependencyname_version as dependencyname

There is currently no clean way to do this. The best you can hope is for this hack to work.

I'd rather ditch one of the two libs and replace it with an equivalent, or patch it to accept the new version of the dependency and give the patch back to the community.

这篇关于使用 pip 安装多个版本的包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 22:48