Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Module To Detect Linux Distro Version

Is there an existing python module that can be used to detect which distro of Linux and which version of the distro is currently installed.

For example:

  • RedHat Enterprise 5
  • Fedora 11
  • Suse Enterprise 11
  • etc....

I can make my own module by parsing various files like /etc/redhat-release but I was wondering if a module already exists?

Cheers, Ivan

like image 459
Ivan Novick Avatar asked Dec 29 '09 22:12

Ivan Novick


People also ask

How do I find the version of Python on Linux?

The easiest way to check Python version in Linux is using python -V command. All we need is to open the terminal then type python -V in the prompt.

What are distro packages?

The distro package ( distro stands for Linux Distribution) provides information about the Linux distribution it runs on, such as a reliable machine-readable distro ID, or version information. It is the recommended replacement for Python's original platform.


1 Answers

Look up the docs for the platform module: http://docs.python.org/library/platform.html

Example:

>>> platform.uname()
('Linux', 'localhost', '2.6.31.5-desktop-1mnb', '#1 SMP Fri Oct 23 00:05:22 EDT 2009', 'x86_64', 'AMD Athlon(tm) 64 X2 Dual Core Processor 3600+')
>>> platform.linux_distribution()
('Mandriva Linux', '2010.0', 'Official')
like image 168
Antoine P. Avatar answered Oct 06 '22 16:10

Antoine P.