Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

platform.linux_distribution() deprecated - what are the alternatives?

Tags:

python

linux

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.

like image 983
David258 Avatar asked Mar 29 '18 11:03

David258


1 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().

like image 69
jmd_dk Avatar answered Sep 19 '22 17:09

jmd_dk