101

What are the possible return values from the following command?

import sys
print sys.platform

I know there is a lot of possibilities, so I'm mainly interested in the "main" ones (Windows, Linux, Mac OS)

dbr
  • 165,801
  • 69
  • 278
  • 343

5 Answers5

183
┍━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━┑
│ System              │ Value               │
┝━━━━━━━━━━━━━━━━━━━━━┿━━━━━━━━━━━━━━━━━━━━━┥
│ Linux               │ linux or linux2 (*) │
│ Windows             │ win32               │
│ Windows/Cygwin      │ cygwin              │
│ Windows/MSYS2       │ msys                │
│ Mac OS X            │ darwin              │
│ OS/2                │ os2                 │
│ OS/2 EMX            │ os2emx              │
│ RiscOS              │ riscos              │
│ AtheOS              │ atheos              │
│ FreeBSD 7           │ freebsd7            │
│ FreeBSD 8           │ freebsd8            │
│ FreeBSD N           │ freebsdN            │
│ OpenBSD 6           │ openbsd6            │
│ AIX                 │ aix (**)            │
┕━━━━━━━━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━┙

(*) Prior to Python 3.3, the value for any Linux version is always linux2; after, it is linux.

(**) Prior Python 3.8 could also be aix5 or aix7; use sys.platform.startswith()

Niko Föhr
  • 28,336
  • 10
  • 93
  • 96
ICB
  • 1,839
  • 2
  • 11
  • 2
39

Mac OS X (10.4, 10.5, 10.7, 10.8):

darwin

Linux (2.6 kernel):

linux2

Windows XP 32 bit:

win32

Versions in brackets have been checked - other/newer versions are likely to be the same.

Adam Lewis
  • 7,017
  • 7
  • 44
  • 62
dbr
  • 165,801
  • 69
  • 278
  • 343
  • What about OS X versions higher than 10.5, are they also labeled under 'darwin'? What about Linux kernel versions higher than 2.6? Windows versions higher than XP? – Dennis Nov 17 '12 at 04:44
  • @Dennis Clarified in answer - the listed versions are the ones I have checked. I'm almost certain all OS X versions will be `darwin`, all 2.x linux kernels will be `linux2`, and Windows will be win32 or win64.. but, I've not checked – dbr Nov 17 '12 at 14:22
  • 1
    Newer versions of Linux may have "linux3" instead of "linux2". – MarioVilas Sep 06 '13 at 10:00
  • 4
    @MarioVilas: No, Python stuck to linux2 even for linux3 kernels because there is no difference from Python's perspective. – Martijn Pieters Nov 22 '13 at 14:47
  • 4
    A 64 bit Python installation on 64 bit Windows will also output "win32". Using `platform.system()` may be a less confusing solution ("Windows" vs "Linux"). – Daniel F Aug 24 '14 at 23:04
  • The list is larger and isn't clearly [documented] (https://docs.python.org/2/library/sys.html), for example in OpenBSD is "openbsd6" – rfmoz Dec 28 '17 at 19:51
22

As others have indicated, sys.platform is derived from the name that the system vendor gives their system. However, Python also adds plat- to sys.path, so you can look at all the plat-* directories in the Python distribution.

This gives you the list

aix3 aix4 atheos beos5 darwin freebsd2 freebsd3 freebsd4 freebsd5 freebsd6 freebsd7 generic irix5 irix6 linux2 mac netbsd1 next3 os2emx riscos sunos5 unixware7

Of course, sys.platform can have additional values, when Python gets compiled on a system for which no platform-specific directory has been created.

From here.

xOneca
  • 842
  • 9
  • 20
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
9

FreeBSD 7.0: freebsd7. FreeBSD8 but build performed on previous version, same answer.

So be aware you get the platform used for the build, not necessarely the one you're running on.

Keltia
  • 14,535
  • 3
  • 29
  • 30
1

As of Dec 29 2013, OS X 10.9.1 Mavericks is still labeled Darwin.

Jason Elwood
  • 1,315
  • 2
  • 10
  • 12
  • 1
    Darwin is the OS X kernel. To get the OS X version number, use [platform.mac_ver()](https://docs.python.org/2/library/platform.html#platform.mac_ver) – wolfd Jun 29 '15 at 17:23