简体   繁体   中英

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.

Can the same be done in Python?

To be more specific, I work on a Python project that uses some 3rd-party libraries, such as 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.

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.

Is it possible to resolve this problem cleanly in 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..

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. I do it on Windows though.

你可能想看看virtualenv

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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