基于可用操作系统库版本的 pip 要求 [英] pip requirement based on available OS library version

查看:57
本文介绍了基于可用操作系统库版本的 pip 要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于 pygit2 的 python 包.pygit2 依赖于 libgit2.

Ubuntu 18.04 版本为 libgit2-2.6

Ubuntu 18.10 版本为 libgit2-2.7

在我的requirements.txt/Pipfile中,如果我有"pygit2" = "==0.26.4",它可以在18.04运行(在执行apt-get install libgit2-dev) 但不是在 18.10.类似地,取决于 "*""==0.27" 在 18.10 上有效,但在 18.04 上无效.我还没有尝试过其他发行版.有没有一种方法可以指定,

如果 os 有 libgit2-2.6pygit2 == 0.26.4否则如果 os 有 libgit2-2.7pygit2 == 0.27.x

我尝试了 pygit2>=0.26.4,但不适用于 18.04.

解决方案

您可以使用 platform 模块指定特定版本的模块.

<预><代码>>>>platform.platform().split('-')[6]'18.04'>>>>>>进口平台>>>如果 platform.platform() 中的18.04":... 打印(安装 18.04 模块")... elif "18.10" 在 platform.platform() 中:... print("安装 18.10 模块")...安装 18.04 模块>>>

希望有帮助.

I am developing a python package based on pygit2. pygit2 depends on libgit2.

Ubuntu 18.04 has version libgit2-2.6

Ubuntu 18.10 has version libgit2-2.7

In my requirements.txt/Pipfile, if I have "pygit2" = "==0.26.4", it works in 18.04 (after doing apt-get install libgit2-dev) but not in 18.10. Similarly, depending on "*" or "==0.27" works on 18.10 but not on 18.04. I have not tried on other distros. Is there a way I can specify like,

if os has libgit2-2.6
    pygit2 == 0.26.4
else if os has libgit2-2.7
    pygit2 == 0.27.x

I tried pygit2>=0.26.4, didn't work for 18.04.

解决方案

You can specify version specific modules by using platform module.

>>> platform.platform().split('-')[6]
'18.04'
>>>

>>> import platform
>>> if "18.04" in platform.platform():
...   print("install 18.04 modules")
... elif "18.10" in platform.platform():
...   print("Install 18.10 modules")
...
install 18.04 modules
>>>

Hope it helps.

这篇关于基于可用操作系统库版本的 pip 要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆