你可以使用
distro project:
$pip install distro
$python
>>> import distro
>>> distro.linux_distribution(full_distribution_name=False)
('centos', '7.1.1503', 'Core')
It is a renewed alternative implementation for Python’s original platform.linux_distribution function, but it also provides much more functionality which isn’t necessarily Python bound like a command-line interface
该方法已从平台库中删除,因为检测您使用的分发的正确方法更改的速度可能比Python发布计划更快.从上面的错误报告:
The stdlib is not the right place for things that change this often. Just look at how many semi standards we’ve seen in the last few years. There’s no point in trying to follow these in a slow moving code base as the Python stdlib. It’s much better to put the functionality into a PyPI module which can be updated much more frequently.