Answer a question

As of Python 3.5 platform.linux_distribution() is deprecated and it's planned to be removed from Python 3.7.

Is there anything I could uses instead of platform.linux_distribution()?

platform.uname() doesn't yield the information I need. I'm running the code in a Docker container and platform.uname() returns the details for the host machine, not the image.

In particular, I'm building a portable Linux distribution and I want to test it on the canonical CentOS 5.11 distribution. I'm looking for a simple way to identify the OS to identify/tag the build results.

Answers

According to Deprecated platform.linux_distribution() and platform.dist(), the platform.linux_distribution() will be removed from Python 3.7. It is indeed still present in Python 3.6. The recommended alternative is the distro package.

After installing the package, you can use the following code.

import distro
distro.linux_distribution()

In newer versions of the distro package, distro.linux_distribution() has been deprecated. Instead, the package makes available distro.id(), distro.version(), and distro.name().

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐