platform.linux_distribution() deprecated - what ar

2020-08-17 07:14发布

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?

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.

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 linux
2条回答
来,给爷笑一个
2楼-- · 2020-08-17 07:16

Another option is platform.uname():

>>> import platform
>>> platform.uname()
uname_result(system='Linux', node='lensman', release='4.19.84', version='#1-NixOS SMP Tue Nov 12 18:21:46 UTC 2019', machine='x86_64', processor='')
查看更多
来,给爷笑一个
3楼-- · 2020-08-17 07:38

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.

After installing the package, you can do

import distro
distro.linux_distribution()
查看更多
登录 后发表回答