如何知道系统是Python中的Debian还是CentOS?

Wil*_*iam 5 python debian apt centos yum

我想通过python编写一些安装脚本,它应该知道操作系统选择apt命令或yum命令.

似乎sys.platform可以告诉'win32'或其他人,但是如何知道它正在使用Python中的Debian或CentOS?

Joe*_*ton 9

标准库中的平台模块具有您想要的功能.

import platform
print platform.linux_distribution()
Run Code Online (Sandbox Code Playgroud)

  • 正如更新一样,“platform.linux_distribution()”已被贬值。建议使用PyPI库代替,例如发行版https://github.com/nir0s/distro,有关它的讨论https://bugs.python.org/msg207415 (2认同)