platform.linux_distribution()已过时-有哪些替代方案? [英] platform.linux_distribution() deprecated - what are the alternatives?
问题描述
从Python> 3.5开始,不推荐使用函数platform.linux_distribution()
:
https://docs.python.org/3.5/library/platform.html #platform.linux_distribution
As of Python >3.5 the function platform.linux_distribution()
is being deprecated:
https://docs.python.org/3.5/library/platform.html#platform.linux_distribution
有什么可以直接替代的吗?
Is there anything that directly replaces it?
不幸的是,由于我是在docker容器中构建的,所以platform.uname()无法提供所需的信息,这将返回主机的详细信息而不是映像.
Unfortunately for me, platform.uname() doesn't yield the information I need since I'm building in a docker container and this returns the details of the host machine not the image.
尤其是:我正在构建一个可移植的linux发行版( https://www .python.org/dev/peps/pep-0513/),并希望在规范的CentOS 5.11发行版上对其进行测试.我正在寻找一种识别操作系统的简单方法,以便可以识别/标记构建结果.
In particular: I'm building a portable linux distribution (https://www.python.org/dev/peps/pep-0513/) and want to test it on the canonical CentOS 5.11 distribution. I'm looking for a simple way to identify the OS so I can identify/tag the build results.
推荐答案
根据此,将从Python 3.7开始弃用platform.linux_distribution()
.我可以确认它确实存在于3.6中.该链接推荐使用发行版包作为替代.
According to this, the platform.linux_distribution()
will be deprecated beginning with Python 3.7. I can confirm that it is indeed present in 3.6. The link recommend the distro package as the alternative.
安装软件包后,您可以
import distro
distro.linux_distribution()
这篇关于platform.linux_distribution()已过时-有哪些替代方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!