<p>What do I need to look at to see whether I'm on Windows or Unix, etc?</p>

[{'answer_id': 1857, 'author': 'Louis Brandy', 'author_id': 2089740, 'author_profile': 'https://Stackoverflow.com/users/2089740', 'pm_score': 11, 'selected': True, 'text': '<pre><code>&gt;&gt;&gt; import os\n&gt;&gt;&gt; os.name\n\'posix\'\n&gt;&gt;&gt; import platform\n&gt;&gt;&gt; platform.system()\n\'Linux\'\n&gt;&gt;&gt; platform.release()\n\'2.6.22-15-generic\'\n</code></pre>\n\n<p>The output of <a href="https://docs.python.org/library/platform.html#platform.system" rel="noreferrer"><code>platform.system()</code></a> is as follows:</p>\n\n<ul>\n<li>Linux: <code>Linux</code></li>\n<li>Mac: <code>Darwin</code></li>\n<li>Windows: <code>Windows</code></li>\n</ul>\n\n<p>See: <a href="https://docs.python.org/library/platform.html" rel="noreferrer"><code>platform</code> — Access to underlying platform’s identifying data</a></p>\n'}, {'answer_id': 1871, 'author': 'Joey deVilla', 'author_id': 216, 'author_profile': 'https://Stackoverflow.com/users/216', 'pm_score': 8, 'selected': False, 'text': '<p><a href="https://stackoverflow.com/a/1857/4298200">Dang -- Louis Brandy beat me to the punch</a>, but that doesn\'t mean I can\'t provide you with the system results for Vista!</p>\n<pre><code>&gt;&gt;&gt; import os\n&gt;&gt;&gt; os.name\n\'nt\'\n&gt;&gt;&gt; import platform\n&gt;&gt;&gt; platform.system()\n\'Windows\'\n&gt;&gt;&gt; platform.release()\n\'Vista\'\n</code></pre>\n<p>...and I can’t believe no one’s posted one for Windows 10 yet:</p>\n<pre><code>&gt;&gt;&gt; import os\n&gt;&gt;&gt; os.name\n\'nt\'\n&gt;&gt;&gt; import platform\n&gt;&gt;&gt; platform.system()\n\'Windows\'\n&gt;&gt;&gt; platform.release()\n\'10\'\n</code></pre>\n'}, {'answer_id': 1879, 'author': 'Mark Harrison', 'author_id': 116, 'author_profile': 'https://Stackoverflow.com/users/116', 'pm_score': 7, 'selected': False, 'text': "<p>For the record here's the results on Mac:</p>\n\n<pre><code>&gt;&gt;&gt; import os\n&gt;&gt;&gt; os.name\n'posix'\n&gt;&gt;&gt; import platform\n&gt;&gt;&gt; platform.system()\n'Darwin'\n&gt;&gt;&gt; platform.release()\n'8.11.1'\n</code></pre>\n"}, {'answer_id': 28426, 'author': 'Moe', 'author_id': 3051, 'author_profile': 'https://Stackoverflow.com/users/3051', 'pm_score': 5, 'selected': False, 'text': '<p>You can also use <a href="https://docs.python.org/library/sys.html#sys.platform" rel="noreferrer"><code>sys.platform</code></a> if you already have imported <code>sys</code> and you don\'t want to import another module</p>\n\n<pre><code>&gt;&gt;&gt; import sys\n&gt;&gt;&gt; sys.platform\n\'linux2\'\n</code></pre>\n'}, {'answer_id': 3021004, 'author': 'Alftheo', 'author_id': 364306, 'author_profile': 'https://Stackoverflow.com/users/364306', 'pm_score': 4, 'selected': False, 'text': '<p>I am using the WLST tool that comes with weblogic, and it doesn\'t implement the platform package. </p>\n\n<pre><code>wls:/offline&gt; import os\nwls:/offline&gt; print os.name\njava \nwls:/offline&gt; import sys\nwls:/offline&gt; print sys.platform\n\'java1.5.0_11\'\n</code></pre>\n\n<p>Apart from patching the system <em>javaos.py</em> (<a href="http://osdir.com/ml/lang.jython.devel/2006-08/msg00035.html" rel="noreferrer">issue with os.system() on windows 2003 with jdk1.5</a>) (which I can\'t do, I have to use weblogic out of the box), this is what I use:</p>\n\n<pre><code>def iswindows():\n  os = java.lang.System.getProperty( "os.name" )\n  return "win" in os.lower()\n</code></pre>\n'}, {'answer_id': 7587420, 'author': 'Elden', 'author_id': 969654, 'author_profile': 'https://Stackoverflow.com/users/969654', 'pm_score': 2, 'selected': False, 'text': '<p>in the same vein....</p>\n\n<pre><code>import platform\nis_windows=(platform.system().lower().find("win") &gt; -1)\n\nif(is_windows): lv_dll=LV_dll("my_so_dll.dll")\nelse:           lv_dll=LV_dll("./my_so_dll.so")\n</code></pre>\n'}, {'answer_id': 7707465, 'author': 'urantialife', 'author_id': 986889, 'author_profile': 'https://Stackoverflow.com/users/986889', 'pm_score': 3, 'selected': False, 'text': "<p>/usr/bin/python3.2</p>\n\n<pre><code>def cls():\n    from subprocess import call\n    from platform import system\n\n    os = system()\n    if os == 'Linux':\n        call('clear', shell = True)\n    elif os == 'Windows':\n        call('cls', shell = True)\n</code></pre>\n"}, {'answer_id': 14231316, 'author': 'Michał Niklas', 'author_id': 22595, 'author_profile': 'https://Stackoverflow.com/users/22595', 'pm_score': 3, 'selected': False, 'text': '<p>For Jython the only way to get os name I found is to check <code>os.name</code> Java property (tried with <code>sys</code>, <code>os</code> and <code>platform</code> modules for Jython 2.5.3 on WinXP):</p>\n\n<pre><code>def get_os_platform():\n    """return platform name, but for Jython it uses os.name Java property"""\n    ver = sys.platform.lower()\n    if ver.startswith(\'java\'):\n        import java.lang\n        ver = java.lang.System.getProperty("os.name").lower()\n    print(\'platform: %s\' % (ver))\n    return ver\n</code></pre>\n'}, {'answer_id': 14477954, 'author': 'Jens Timmerman', 'author_id': 869482, 'author_profile': 'https://Stackoverflow.com/users/869482', 'pm_score': 5, 'selected': False, 'text': '<p>If you want user readable data but still detailed, you can use <a href="http://docs.python.org/library/platform.html#platform.platform" rel="nofollow noreferrer">platform.platform()</a></p>\n<pre><code>&gt;&gt;&gt; import platform\n&gt;&gt;&gt; platform.platform()\n\'Linux-3.3.0-8.fc16.x86_64-x86_64-with-fedora-16-Verne\'\n</code></pre>\n<p>Here\'s a few different possible calls you can make to identify where you are, linux_distribution and dist are removed in recent python versions.</p>\n<pre><code>import platform\nimport sys\n\ndef linux_distribution():\n  try:\n    return platform.linux_distribution()\n  except:\n    return &quot;N/A&quot;\n\ndef dist():\n  try:\n    return platform.dist()\n  except:\n    return &quot;N/A&quot;\n\nprint(&quot;&quot;&quot;Python version: %s\ndist: %s\nlinux_distribution: %s\nsystem: %s\nmachine: %s\nplatform: %s\nuname: %s\nversion: %s\nmac_ver: %s\n&quot;&quot;&quot; % (\nsys.version.split(\'\\n\'),\nstr(dist()),\nlinux_distribution(),\nplatform.system(),\nplatform.machine(),\nplatform.platform(),\nplatform.uname(),\nplatform.version(),\nplatform.mac_ver(),\n))\n</code></pre>\n<p>The outputs of this script ran on a few different systems (Linux, Windows, Solaris, MacOS) and architectures (x86, x64, Itanium, power pc, sparc) is available here: <a href="https://github.com/hpcugent/easybuild/wiki/OS_flavor_name_version" rel="nofollow noreferrer">https://github.com/hpcugent/easybuild/wiki/OS_flavor_name_version</a></p>\n<p>Ubuntu 12.04 server for example gives:</p>\n<pre><code>Python version: [\'2.6.5 (r265:79063, Oct  1 2012, 22:04:36) \', \'[GCC 4.4.3]\']\ndist: (\'Ubuntu\', \'10.04\', \'lucid\')\nlinux_distribution: (\'Ubuntu\', \'10.04\', \'lucid\')\nsystem: Linux\nmachine: x86_64\nplatform: Linux-2.6.32-32-server-x86_64-with-Ubuntu-10.04-lucid\nuname: (\'Linux\', \'xxx\', \'2.6.32-32-server\', \'#62-Ubuntu SMP Wed Apr 20 22:07:43 UTC 2011\', \'x86_64\', \'\')\nversion: #62-Ubuntu SMP Wed Apr 20 22:07:43 UTC 2011\nmac_ver: (\'\', (\'\', \'\', \'\'), \'\')\n</code></pre>\n'}, {'answer_id': 14885455, 'author': 'Eric', 'author_id': 102441, 'author_profile': 'https://Stackoverflow.com/users/102441', 'pm_score': 3, 'selected': False, 'text': '<p>Interesting results on windows 8:</p>\n\n<pre><code>&gt;&gt;&gt; import os\n&gt;&gt;&gt; os.name\n\'nt\'\n&gt;&gt;&gt; import platform\n&gt;&gt;&gt; platform.system()\n\'Windows\'\n&gt;&gt;&gt; platform.release()\n\'post2008Server\'\n</code></pre>\n\n<p><strong>Edit:</strong> That\'s a <a href="http://bugs.python.org/issue16176" rel="noreferrer">bug</a></p>\n'}, {'answer_id': 15674751, 'author': 'sunil', 'author_id': 762649, 'author_profile': 'https://Stackoverflow.com/users/762649', 'pm_score': 3, 'selected': False, 'text': "<p>If you not looking for the kernel version etc, but looking for the linux distribution you may want to use the following </p>\n\n<p>in python2.6+ </p>\n\n<pre><code>&gt;&gt;&gt; import platform\n&gt;&gt;&gt; print platform.linux_distribution()\n('CentOS Linux', '6.0', 'Final')\n&gt;&gt;&gt; print platform.linux_distribution()[0]\nCentOS Linux\n&gt;&gt;&gt; print platform.linux_distribution()[1]\n6.0\n</code></pre>\n\n<p>in python2.4</p>\n\n<pre><code>&gt;&gt;&gt; import platform\n&gt;&gt;&gt; print platform.dist()\n('centos', '6.0', 'Final')\n&gt;&gt;&gt; print platform.dist()[0]\ncentos\n&gt;&gt;&gt; print platform.dist()[1]\n6.0\n</code></pre>\n\n<p>Obviously, this will work only if you are running this on linux. If you want to have more generic script across platforms, you can mix this with code samples given in other answers.</p>\n"}, {'answer_id': 25863224, 'author': 'user3928804', 'author_id': 3928804, 'author_profile': 'https://Stackoverflow.com/users/3928804', 'pm_score': 7, 'selected': False, 'text': '<p>Sample code to differentiate operating systems using Python:</p>\n<pre><code>import sys\n\nif sys.platform.startswith(&quot;linux&quot;):  # could be &quot;linux&quot;, &quot;linux2&quot;, &quot;linux3&quot;, ...\n    # linux\nelif sys.platform == &quot;darwin&quot;:\n    # MAC OS X\nelif sys.platform == &quot;win32&quot;:\n    # Windows (either 32-bit or 64-bit)\n</code></pre>\n'}, {'answer_id': 26643177, 'author': 'Stefan Gruenwald', 'author_id': 1751920, 'author_profile': 'https://Stackoverflow.com/users/1751920', 'pm_score': 2, 'selected': False, 'text': '<p>Check the available tests with module platform and print the answer out for your system:</p>\n\n<pre><code>import platform\n\nprint dir(platform)\n\nfor x in dir(platform):\n    if x[0].isalnum():\n        try:\n            result = getattr(platform, x)()\n            print "platform."+x+": "+result\n        except TypeError:\n            continue\n</code></pre>\n'}, {'answer_id': 27990199, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': False, 'text': '<p>try this:</p>\n\n<pre><code>import os\n\nos.uname()\n</code></pre>\n\n<p>and you can make it :</p>\n\n<pre><code>info=os.uname()\ninfo[0]\ninfo[1]\n</code></pre>\n'}, {'answer_id': 31296120, 'author': 'the', 'author_id': 1245190, 'author_profile': 'https://Stackoverflow.com/users/1245190', 'pm_score': 3, 'selected': False, 'text': "<p>Watch out if you're on Windows with Cygwin where <code>os.name</code> is <code>posix</code>.</p>\n\n<pre><code>&gt;&gt;&gt; import os, platform\n&gt;&gt;&gt; print os.name\nposix\n&gt;&gt;&gt; print platform.system()\nCYGWIN_NT-6.3-WOW\n</code></pre>\n"}, {'answer_id': 39051901, 'author': 'G M', 'author_id': 2132157, 'author_profile': 'https://Stackoverflow.com/users/2132157', 'pm_score': 2, 'selected': False, 'text': "<p>You can also use only platform module without importing os module to get all the information.</p>\n\n<pre><code>&gt;&gt;&gt; import platform\n&gt;&gt;&gt; platform.os.name\n'posix'\n&gt;&gt;&gt; platform.uname()\n('Darwin', 'mainframe.local', '15.3.0', 'Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64', 'x86_64', 'i386')\n</code></pre>\n\n<p>A nice and tidy layout for reporting purpose can be achieved using this line:</p>\n\n<pre><code>for i in zip(['system','node','release','version','machine','processor'],platform.uname()):print i[0],':',i[1]\n</code></pre>\n\n<p>That gives this output:</p>\n\n<pre><code>system : Darwin\nnode : mainframe.local\nrelease : 15.3.0\nversion : Darwin Kernel Version 15.3.0: Thu Dec 10 18:40:58 PST 2015; root:xnu-3248.30.4~1/RELEASE_X86_64\nmachine : x86_64\nprocessor : i386\n</code></pre>\n\n<p>What is missing usually is the operating system version but you should know if you are running windows, linux or mac a platform indipendent way is to use this test:</p>\n\n<pre><code>In []: for i in [platform.linux_distribution(),platform.mac_ver(),platform.win32_ver()]:\n   ....:     if i[0]:\n   ....:         print 'Version: ',i[0]\n</code></pre>\n"}, {'answer_id': 45679447, 'author': 'whackamadoodle3000', 'author_id': 7848065, 'author_profile': 'https://Stackoverflow.com/users/7848065', 'pm_score': 4, 'selected': False, 'text': '<p>How about a new answer:</p>\n\n<pre><code>import psutil\npsutil.MACOS   #True (OSX is deprecated)\npsutil.WINDOWS #False\npsutil.LINUX   #False \n</code></pre>\n\n<p>This would be the output if I was using MACOS</p>\n'}, {'answer_id': 48244490, 'author': 'Alexander Calvert', 'author_id': 9214024, 'author_profile': 'https://Stackoverflow.com/users/9214024', 'pm_score': 2, 'selected': False, 'text': "<p>If you are running macOS X and run <code>platform.system()</code> you get darwin\nbecause macOS X is built on Apple's Darwin OS. Darwin is the kernel of macOS X and is essentially macOS X without the GUI.</p>\n"}, {'answer_id': 52542427, 'author': 'Memin', 'author_id': 2234161, 'author_profile': 'https://Stackoverflow.com/users/2234161', 'pm_score': 1, 'selected': False, 'text': '<p>How about a simple Enum implementation like the following? No need for external libs!</p>\n\n<pre><code>import platform\nfrom enum import Enum\nclass OS(Enum):\n    def checkPlatform(osName):\n        return osName.lower()== platform.system().lower()\n\n    MAC = checkPlatform("darwin")\n    LINUX = checkPlatform("linux")\n    WINDOWS = checkPlatform("windows")  #I haven\'t test this one\n</code></pre>\n\n<p>Simply you can access with Enum value</p>\n\n<pre><code>if OS.LINUX.value:\n    print("Cool it is Linux")\n</code></pre>\n\n<p>P.S It is python3</p>\n'}, {'answer_id': 54421790, 'author': 'hoijui', 'author_id': 586229, 'author_profile': 'https://Stackoverflow.com/users/586229', 'pm_score': 2, 'selected': False, 'text': '<p>This solution works for both <code>python</code> and <code>jython</code>.</p>\n\n<p>module <em>os_identify.py</em>:</p>\n\n<pre><code>import platform\nimport os\n\n# This module contains functions to determine the basic type of\n# OS we are running on.\n# Contrary to the functions in the `os` and `platform` modules,\n# these allow to identify the actual basic OS,\n# no matter whether running on the `python` or `jython` interpreter.\n\ndef is_linux():\n    try:\n        platform.linux_distribution()\n        return True\n    except:\n        return False\n\ndef is_windows():\n    try:\n        platform.win32_ver()\n        return True\n    except:\n        return False\n\ndef is_mac():\n    try:\n        platform.mac_ver()\n        return True\n    except:\n        return False\n\ndef name():\n    if is_linux():\n        return "Linux"\n    elif is_windows():\n        return "Windows"\n    elif is_mac():\n        return "Mac"\n    else:\n        return "&lt;unknown&gt;" \n</code></pre>\n\n<p>Use like this:</p>\n\n<pre><code>import os_identify\n\nprint "My OS: " + os_identify.name()\n</code></pre>\n'}, {'answer_id': 54582331, 'author': 'not2qubit', 'author_id': 1147688, 'author_profile': 'https://Stackoverflow.com/users/1147688', 'pm_score': 1, 'selected': False, 'text': '<p>You can look at the code in <strong><a href="https://github.com/E3V3A/pip-date" rel="nofollow noreferrer"><code>pyOSinfo</code></a></strong> which is part of the <strong>pip-date</strong> package, to get the most relevant OS information, as seen from your Python distribution. </p>\n\n<p>One of the most common reasons people want to check their OS is for terminal compatibility and if certain system commands are available. Unfortunately, the success of this checking is somewhat dependent on your python installation and OS. For example, <em><code>uname</code></em> is not available on most Windows python packages. The above python program will show you the output of the most commonly used built-in functions, already provided by <code>os, sys, platform, site</code>.</p>\n\n<p><a href="https://i.stack.imgur.com/3PfPS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3PfPS.png" alt="enter image description here"></a></p>\n\n<p>So the best way to get only the essential code is looking at <em>that</em> as an example. (I guess I could have just pasted it here, but that would not have been politically correct.) </p>\n'}, {'answer_id': 54837707, 'author': 'coldfix', 'author_id': 650222, 'author_profile': 'https://Stackoverflow.com/users/650222', 'pm_score': 6, 'selected': False, 'text': "<p>I started a bit more systematic listing of what values you can expect using the various modules (feel free to edit and add your system):</p>\n<h1>Linux (64bit) + WSL</h1>\n<pre><code>                            x86_64            aarch64\n                            ------            -------\nos.name                     posix             posix\nsys.platform                linux             linux\nplatform.system()           Linux             Linux\nsysconfig.get_platform()    linux-x86_64      linux-aarch64\nplatform.machine()          x86_64            aarch64\nplatform.architecture()     ('64bit', '')     ('64bit', 'ELF')\n</code></pre>\n<ul>\n<li>tried with archlinux and mint, got same results</li>\n<li>on python2 <code>sys.platform</code> is suffixed by kernel version, e.g. <code>linux2</code>, everything else stays identical</li>\n<li>same output on Windows Subsystem for Linux (tried with ubuntu 18.04 LTS), except <code>platform.architecture() = ('64bit', 'ELF')</code></li>\n</ul>\n<h1>WINDOWS (64bit)</h1>\n<p>(with 32bit column running in the 32bit subsystem)</p>\n<pre><code>official python installer   64bit                     32bit\n-------------------------   -----                     -----\nos.name                     nt                        nt\nsys.platform                win32                     win32\nplatform.system()           Windows                   Windows\nsysconfig.get_platform()    win-amd64                 win32\nplatform.machine()          AMD64                     AMD64\nplatform.architecture()     ('64bit', 'WindowsPE')    ('64bit', 'WindowsPE')\n\nmsys2                       64bit                     32bit\n-----                       -----                     -----\nos.name                     posix                     posix\nsys.platform                msys                      msys\nplatform.system()           MSYS_NT-10.0              MSYS_NT-10.0-WOW\nsysconfig.get_platform()    msys-2.11.2-x86_64        msys-2.11.2-i686\nplatform.machine()          x86_64                    i686\nplatform.architecture()     ('64bit', 'WindowsPE')    ('32bit', 'WindowsPE')\n\nmsys2                       mingw-w64-x86_64-python3  mingw-w64-i686-python3\n-----                       ------------------------  ----------------------\nos.name                     nt                        nt\nsys.platform                win32                     win32\nplatform.system()           Windows                   Windows\nsysconfig.get_platform()    mingw                     mingw\nplatform.machine()          AMD64                     AMD64\nplatform.architecture()     ('64bit', 'WindowsPE')    ('32bit', 'WindowsPE')\n\ncygwin                      64bit                     32bit\n------                      -----                     -----\nos.name                     posix                     posix\nsys.platform                cygwin                    cygwin\nplatform.system()           CYGWIN_NT-10.0            CYGWIN_NT-10.0-WOW\nsysconfig.get_platform()    cygwin-3.0.1-x86_64       cygwin-3.0.1-i686\nplatform.machine()          x86_64                    i686\nplatform.architecture()     ('64bit', 'WindowsPE')    ('32bit', 'WindowsPE')\n\n</code></pre>\n<p>Some remarks:</p>\n<ul>\n<li>there is also <code>distutils.util.get_platform()</code> which is identical to `sysconfig.get_platform</li>\n<li>anaconda on windows is same as official python windows installer</li>\n<li>I don't have a Mac nor a true 32bit system and was not motivated to do it online</li>\n</ul>\n<p>To compare with your system, simply run this script (and please append results here if missing :)</p>\n<pre><code>from __future__ import print_function\nimport os\nimport sys\nimport platform\nimport sysconfig\n\nprint(&quot;os.name                      &quot;,  os.name)\nprint(&quot;sys.platform                 &quot;,  sys.platform)\nprint(&quot;platform.system()            &quot;,  platform.system())\nprint(&quot;sysconfig.get_platform()     &quot;,  sysconfig.get_platform())\nprint(&quot;platform.machine()           &quot;,  platform.machine())\nprint(&quot;platform.architecture()      &quot;,  platform.architecture())\n</code></pre>\n"}, {'answer_id': 56258096, 'author': 'tudor', 'author_id': 11539736, 'author_profile': 'https://Stackoverflow.com/users/11539736', 'pm_score': 1, 'selected': False, 'text': '<p>I am late to the game but, just in case anybody needs it, this a function I use to make adjustments on my code so it runs on Windows, Linux and MacOs:</p>\n\n<pre class="lang-py prettyprint-override"><code>import sys\ndef get_os(osoptions={\'linux\':\'linux\',\'Windows\':\'win\',\'macos\':\'darwin\'}):\n    \'\'\'\n    get OS to allow code specifics\n    \'\'\'   \n    opsys = [k for k in osoptions.keys() if sys.platform.lower().find(osoptions[k].lower()) != -1]\n    try:\n        return opsys[0]\n    except:\n        return \'unknown_OS\'\n</code></pre>\n'}, {'answer_id': 58071295, 'author': 'Shital Shah', 'author_id': 207661, 'author_profile': 'https://Stackoverflow.com/users/207661', 'pm_score': 7, 'selected': False, 'text': '<p><strong>Short Story</strong></p>\n\n<p>Use <code>platform.system()</code>. It returns <code>Windows</code>, <code>Linux</code> or <code>Darwin</code> (for OSX).</p>\n\n<p><strong>Long Story</strong></p>\n\n<p>There are 3 ways to get OS in Python, each with its own pro and cons:</p>\n\n<p><strong>Method 1</strong></p>\n\n<pre><code>&gt;&gt;&gt; import sys\n&gt;&gt;&gt; sys.platform\n\'win32\'  # could be \'linux\', \'linux2, \'darwin\', \'freebsd8\' etc\n</code></pre>\n\n<p>How this works (<a href="https://github.com/python/cpython/blob/b82e17e626f7b1cd98aada0b1ebb65cb9f8fb184/Python/sysmodule.c#L1478" rel="noreferrer">source</a>): Internally it calls OS APIs to get name of the OS as defined by OS. See <a href="https://stackoverflow.com/a/13874620/207661">here</a> for various OS-specific values.</p>\n\n<p>Pro: No magic, low level.</p>\n\n<p>Con: OS version dependent, so best not to use directly. </p>\n\n<p><strong>Method 2</strong></p>\n\n<pre><code>&gt;&gt;&gt; import os\n&gt;&gt;&gt; os.name\n\'nt\'  # for Linux and Mac it prints \'posix\'\n</code></pre>\n\n<p>How this works (<a href="https://github.com/python/cpython/blob/3.7/Lib/os.py#L48" rel="noreferrer">source</a>): Internally it checks if python has OS-specific modules called posix or nt. </p>\n\n<p>Pro: Simple to check if posix OS</p>\n\n<p>Con: no differentiation between Linux or OSX.</p>\n\n<p><strong>Method 3</strong></p>\n\n<pre><code>&gt;&gt;&gt; import platform\n&gt;&gt;&gt; platform.system()\n\'Windows\' # for Linux it prints \'Linux\', Mac it prints `\'Darwin\'\n</code></pre>\n\n<p>How this works (<a href="https://github.com/python/cpython/blob/3.7/Lib/platform.py#L949" rel="noreferrer">source</a>): Internally it will eventually call internal OS APIs, get OS version-specific name like \'win32\' or \'win16\' or \'linux1\' and then normalize to more generic names like \'Windows\' or \'Linux\' or \'Darwin\' by applying several heuristics. </p>\n\n<p>Pro: Best portable way for Windows, OSX and Linux.</p>\n\n<p>Con: Python folks must keep normalization heuristic up to date.</p>\n\n<p><strong>Summary</strong></p>\n\n<ul>\n<li>If you want to check if OS is Windows or Linux or OSX then the most reliable way is <code>platform.system()</code>.</li>\n<li>If you want to make OS-specific calls but via built-in Python modules <code>posix</code> or <code>nt</code> then use <code>os.name</code>.</li>\n<li>If you want to get raw OS name as supplied by OS itself then use <code>sys.platform</code>.</li>\n</ul>\n'}, {'answer_id': 59863131, 'author': 'robmsmt', 'author_id': 738515, 'author_profile': 'https://Stackoverflow.com/users/738515', 'pm_score': 3, 'selected': False, 'text': '<p>I know this is an old question but I believe that my answer is one that might be helpful to some people who are looking for an easy, simple to understand pythonic way to detect OS in their code. Tested on python3.7</p>\n\n<pre><code>from sys import platform\n\n\nclass UnsupportedPlatform(Exception):\n    pass\n\n\nif "linux" in platform:\n    print("linux")\nelif "darwin" in platform:\n    print("mac")\nelif "win" in platform:\n    print("windows")\nelse:\n    raise UnsupportedPlatform\n</code></pre>\n'}, {'answer_id': 64444776, 'author': 'Jossef Harush Kadouri', 'author_id': 3191896, 'author_profile': 'https://Stackoverflow.com/users/3191896', 'pm_score': 4, 'selected': False, 'text': '<p>Use <a href="https://docs.python.org/3/library/platform.html#platform.system" rel="noreferrer">platform.system()</a></p>\n<blockquote>\n<p>Returns the system/OS name, such as \'Linux\', \'Darwin\', \'Java\', \'Windows\'. An empty string is returned if the value cannot be determined.</p>\n</blockquote>\n<pre><code>import platform\nsystem = platform.system().lower()\n\nis_windows = system == \'windows\'\nis_linux = system == \'linux\'\nis_mac = system == \'darwin\'\n</code></pre>\n'}, {'answer_id': 74101033, 'author': 'Allan Hawkin', 'author_id': 20265625, 'author_profile': 'https://Stackoverflow.com/users/20265625', 'pm_score': 1, 'selected': False, 'text': '<p>there are alot ways to find this the most easiest way to is to use os package</p>\n<pre><code>import os \nprint(os.name)\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/1854', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/116/']