I have a Python 3.2 program that runs like this:
import platform
sysname = platform.system()
sysver = platform.release()
print(sysname+" "+sysver)
And on windows it returns:
Windows 7
But on Ubuntu and others it returns:
Linux 3.0.0-13-generic
I need something like:
Ubuntu 11.10 or Mint 12
Looks like platform.dist()
and platform.linux_distribution()
are deprecated in Python 3.5 and will be removed in Python 3.8. The following works in Python 2/3
import platform
'ubuntu' in platform.platform().lower()
Example return value
>>> platform.platform()
'Linux-4.10.0-40-generic-x86_64-with-Ubuntu-16.04-xenial'
The currently accepted answer uses a deprecated function. The proper way to do this as of Python 2.6 and later is:
import platform
print(platform.linux_distribution())
The documentation doesn't say if this function is available on non-Linux platforms, but on my local Windows desktop I get:
>>> import platform
>>> print(platform.linux_distribution())
('', '', '')
There's also this, to do something similar on Win32 machines:
>>> print(platform.win32_ver())
('post2008Server', '6.1.7601', 'SP1', 'Multiprocessor Free')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With