Python 3.7及以上:如何确定Linux分布?
Python 3.7 and above: how to determine Linux distribution?
由于 Python Docs 明确指出 platform.linux_distribution()
是:
Deprecated since version 3.5, will be removed in version 3.7.
通过 Python 检测 Linux 分布的正确且面向未来的方法是什么?
那将留给一个包裹。来自此更改的新增内容条目:
The platform.dist()
and platform.linux_distribution()
functions are now deprecated. Linux distributions use too many different ways of describing themselves, so the functionality is left to a package. (Contributed by Vajrasky Kok and Berker Peksag in bpo-1322.)
你可以看看issue 1322 that removed it for a more detailed discussion, there's also a package there already。
Python 标准库将不是您可以执行此操作的地方,因为它会产生维护开销。
您可以使用 distro
project:
$ pip install distro
$ python
>>> import distro
>>> distro.linux_distribution(full_distribution_name=False)
('centos', '7.1.1503', 'Core')
这个项目来自 issue #1322, which led to the deprecation of the function. From the project README:
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
该方法已从 platform
库中删除,因为检测您使用的发行版的正确方法的变化速度可能比 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.
根据 Jim 的回答,此功能将从 Python 中删除。 distro 包似乎是推荐的替代方案:
$ pip3 install --user distro
$ python3
Python 3.6.3 (default, Oct 9 2017, 12:07:10)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import distro
>>> distro.linux_distribution()
('Fedora', '27', 'Twenty Seven')
由于 Python Docs 明确指出 platform.linux_distribution()
是:
Deprecated since version 3.5, will be removed in version 3.7.
通过 Python 检测 Linux 分布的正确且面向未来的方法是什么?
那将留给一个包裹。来自此更改的新增内容条目:
The
platform.dist()
andplatform.linux_distribution()
functions are now deprecated. Linux distributions use too many different ways of describing themselves, so the functionality is left to a package. (Contributed by Vajrasky Kok and Berker Peksag in bpo-1322.)
你可以看看issue 1322 that removed it for a more detailed discussion, there's also a package there already。
Python 标准库将不是您可以执行此操作的地方,因为它会产生维护开销。
您可以使用 distro
project:
$ pip install distro
$ python
>>> import distro
>>> distro.linux_distribution(full_distribution_name=False)
('centos', '7.1.1503', 'Core')
这个项目来自 issue #1322, which led to the deprecation of the function. From the project README:
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
该方法已从 platform
库中删除,因为检测您使用的发行版的正确方法的变化速度可能比 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.
根据 Jim 的回答,此功能将从 Python 中删除。 distro 包似乎是推荐的替代方案:
$ pip3 install --user distro
$ python3
Python 3.6.3 (default, Oct 9 2017, 12:07:10)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import distro
>>> distro.linux_distribution()
('Fedora', '27', 'Twenty Seven')