gpt4 book ai didi

Python 3.7 及以上版本 : how to determine Linux distribution?

转载 作者:IT王子 更新时间:2023-10-29 00:25:39 25 4
gpt4 key购买 nike

Python Docs明确指出 platform.linux_distribution() 是:

Deprecated since version 3.5, will be removed in version 3.7.

通过 Python 检测 Linux 发行版的正确且面向 future 的方法是什么?

最佳答案

您可以使用 distro project :

$ pip install distro
$ python
>>> import distro
>>> distro.linux_distribution(full_distribution_name=False)
('centos', '7.1.1503', 'Core')

这个项目来自 issue #1322 ,这导致了函数的弃用。来自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.

关于Python 3.7 及以上版本 : how to determine Linux distribution?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47873828/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com