Possible values from sys.platform?
Asked Answered
A

5

107

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)

Asch answered 15/1, 2009 at 10:2 Comment(2)
Take a look at docs.python.org/2/library/sys.html#sys.platformKrystakrystal
For Python 3.9 see docs.python.org/3.9/library/sys.html#sys.platformHibbs
A
40

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.

Asch answered 15/1, 2009 at 10:3 Comment(6)
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?Krystakrystal
@Krystakrystal 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 checkedAsch
Newer versions of Linux may have "linux3" instead of "linux2".Bradshaw
@MarioVilas: No, Python stuck to linux2 even for linux3 kernels because there is no difference from Python's perspective.Fleuron
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").Lazare
The list is larger and isn't clearly [documented] (docs.python.org/2/library/sys.html), for example in OpenBSD is "openbsd6"Huddle
B
198
┍━━━━━━━━━━━━━━━━━━━━━┯━━━━━━━━━━━━━━━━━━━━━┑
│ 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()

Breed answered 14/12, 2012 at 7:49 Comment(12)
You should make a list of this.From
Probably the most useful answer as of this writing. Additional karma for the stylish ASCII-art spreadsheet.Nevus
What about current macOS systems? Do they still resolve to darwin?Bystander
I'm getting "linux"Riggle
@Bystander yes.Flaky
The list is larger and isn't clearly documented, for example in OpenBSD it reports "openbsd6"Huddle
What about android?Tractate
What is it for ubuntu ?Inhere
Ubuntu is a Linux distro, but I tested this out anyway and it's linux.Grandiloquent
@G.Vanem, android is considered as linux (or linux2).Unorganized
now with 3.11 there are also emscripten and wasi platform docs.python.org/dev/library/sys.html#sys.platlibdirFlippant
Recent versions of MSYS2 now return cygwin. BEWARE!Metatarsal
A
40

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.

Asch answered 15/1, 2009 at 10:3 Comment(6)
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?Krystakrystal
@Krystakrystal 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 checkedAsch
Newer versions of Linux may have "linux3" instead of "linux2".Bradshaw
@MarioVilas: No, Python stuck to linux2 even for linux3 kernels because there is no difference from Python's perspective.Fleuron
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").Lazare
The list is larger and isn't clearly [documented] (docs.python.org/2/library/sys.html), for example in OpenBSD is "openbsd6"Huddle
T
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.

Tillietillinger answered 15/1, 2009 at 10:4 Comment(3)
By digging through the sourcecode there are a few more common: win32, os2, unknownRef
On Python 3.3 and later linux2 becomes linux. sourceHagy
@Deqing: fixed three years later :)Keilakeily
P
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.

Profusive answered 15/1, 2009 at 10:6 Comment(0)
C
1

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

Cramp answered 29/12, 2013 at 16:13 Comment(1)
Darwin is the OS X kernel. To get the OS X version number, use platform.mac_ver()Hoebart

© 2022 - 2024 — McMap. All rights reserved.