Fix Python – How to identify on which OS Python is running on?

Question

Asked By – Mark Harrison

What do I need to look at to see whether I’m on Windows or Unix, etc?

Now we will see solution for issue: How to identify on which OS Python is running on?


Answer

>>> import os
>>> os.name
'posix'
>>> import platform
>>> platform.system()
'Linux'
>>> platform.release()
'2.6.22-15-generic'

The output of platform.system() is as follows:

  • Linux: Linux
  • Mac: Darwin
  • Windows: Windows

See: platform — Access to underlying platform’s identifying data

This question is answered By – Louis Brandy

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0