Python 3.10+Linuxplatformfunction
platform.freedesktop_os_release()
specific operating systems
A dict read from the os-release file: NAME, ID, VERSION_ID and more. This identifies the Linux distribution; OSError if missing.
Syntax
info = platform.freedesktop_os_release()
It does not return an empty dict on Windows and macOS but raises OSError, so wrap the call in try/except. For decisions in code use ID and ID_LIKE ('ubuntu', 'debian') rather than NAME and PRETTY_NAME, which are for people and change between releases. Android has no os-release file.
Examples
import platform
try:
info = platform.freedesktop_os_release()
print(info['ID']) # → ? например ubuntu
except OSError:
print('нет os-release') # → ? на Windows и macOS
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy