2

我正在开发一个基于pygit2. 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 不起作用。

4

1 回答 1

0

您可以使用模块指定特定于版本的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
>>>

希望能帮助到你。

于 2019-01-15T03:48:55.810 回答