简体   繁体   English

可以在同一个Python安装中共存同一个库的两个版本吗?

[英]Can two versions of the same library coexist in the same Python install?

The C libraries have a nice form of late binding, where the exact version of the library that was used during linking is recorded, and thus an executable can find the correct file, even when several versions of the same library are installed. C库有一种很好的后期绑定形式,其中记录了链接期间使用的库的确切版本,因此即使安装了同一个库的多个版本,可执行文件也可以找到正确的文件。

Can the same be done in Python? 可以在Python中完成相同的操作吗?

To be more specific, I work on a Python project that uses some 3rd-party libraries, such as paramiko. 更具体地说,我使用的是一个使用某些第三方库的Python项目,例如paramiko。 Paramiko is now version 1.7.4, but some distributions carry an older version of it, while supplying about the same version of the Python interpreter. Paramiko现在是版本1.7.4,但是一些发行版带有它的旧版本,同时提供大约相同版本的Python解释器。

Naturally, I would like to support as many configurations as possible, and not just the latest distros. 当然,我想支持尽可能多的配置,而不仅仅是最新的发行版。 But if I upgrade the installed version of paramiko from what an old distro provides, I 1) make life hard for the package manager 2) might break some existing apps due to incompatibilities in the library version and 3) might get broken if the package manager decides to overwrite my custom installation. 但是,如果我从旧的发行版提供的升级paramiko的版本,我1)使包管理器的生活变得困难2)由于库版本中的不兼容性可能会破坏一些现有的应用程序3)如果包管理器可能会破坏决定覆盖我的自定义安装。

Is it possible to resolve this problem cleanly in Python? 是否有可能在Python中干净地解决这个问题? (ie, how would i do the setup, and what should the code look like). (即,我将如何进行设置,以及代码应该是什么样的)。 Ideally, it would just install several versions of a library in site_libraries and let my script select the right one, rather than maintaining a private directory with a set of manually installed libraries.. 理想情况下,它只需在site_libraries中安装多个版本的库,让我的脚本选择正确的版本,而不是使用一组手动安装的库来维护私有目录。

PS: I could compile the Python program to a binary, carrying all the necessary dependencies with it, but it kind of works against the idea of using the interpreter provided by the distro. PS:我可以将Python程序编译成二进制文件,携带所有必需的依赖项,但它有点违背使用发行版提供的解释器的想法。 I do it on Windows though. 我在Windows上做到了。

你可能想看看virtualenv

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

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