Skip to content

Bug issue template uses removed Python function platform.linux_distribution()

The Bug issue template in this repo's issue tracker says to run:

python -c "import platform, socket, sys; system = platform.system(); print('\nPython:           {}'.format(sys.version.splitlines()[0])); print('Operating system: {}'.format(' '.join(platform.linux_distribution()) if system == 'Linux' else 'macOS {}'.format(platform.mac_ver()[0]))); print('Hostname:         {}'.format(socket.getfqdn()))"

which raises the exception

Traceback (most recent call last):
  File "<string>", line 1, in <module>
AttributeError: module 'platform' has no attribute 'linux_distribution'

as this function was removed in Python 3.8 (see deprecation note here).

Assuming we don't need to support Android and probably some niche distros, it seems the replacement platform.freedesktop_os_release() is a suitable replacement. Some of the dict keys are system-dependent, but the docs state that NAME, ID, and PRETTY_NAME are part of the FreeDesktop standard, so I think platform.freedesktop_os_release()['PRETTY_NAME'] is probably the best substitute.