【问题标题】:pip requirement based on available OS library version基于可用操作系统库版本的 pip 要求
【发布时间】:2019-06-09 01:50:00
【问题描述】:

我正在开发一个基于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 上不工作。我还没有尝试过其他发行版。有没有办法我可以指定像,

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

我尝试了pygit2>=0.26.4,但在 18.04 中不起作用。

【问题讨论】:

    标签: python python-3.x pip pypi pygit2


    【解决方案1】:

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

    >>> 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
    >>>
    

    希望对你有帮助。

    【讨论】:

    • 问题是如何将条件放在requirements.txtPipfile 中?
    • 谢谢!即使有一种使用platform 添加的方法,这也使它特定于Ubuntu,我希望它基于libgit2 版本。这不适用于数千个发行版。
    猜你喜欢
    • 2013-04-07
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 2015-08-26
    • 1970-01-01
    • 2012-06-08
    • 2012-02-05
    • 2022-01-22
    相关资源
    最近更新 更多