The main way to identify the current OS is to use
process.platform
(or the identical
os.platform()
).
The os
core module offers some finer-grained
identification methods but those are rarely needed:
os.type()
is similar but slighly more precise.os.release()
returns the OS version number, e.g.3.11.0-14-generic
(Linux),18.0.0
(Mac) or10.0.17763
(Windows).os.version()
returns a more detailed OS version number, e.g.#32-Ubuntu SMP Fri Jan 31 20:24:34 UTC 2020
(Linux),Darwin Kernel Version 18.0.0: Wed Aug 22 20:13:40 PDT 2018; root:xnu-4903.201.2~1/RELEASE_X86_64
(Mac) orWindows 10 Home
(Windows).os.arch()
(or the identicalprocess.arch
) returns the CPU architecture, e.g.arm
orx64
.os.endianness()
returns the CPU endianness, i.e.BE
orLE
.navigator.platform
can also be used, which combinesprocess.platform
andprocess.arch
.
Some projects allow retrieving:
getos
: the Linux distribution name.osname
(and the relatedwindows-release
andmacos-release
): the OS name and version in a human-friendly way.is-windows
: whether current OS is Windows, including through MSYS and Cygwin.is-wsl
: whether current OS is Windows though WSL.
When using OS-specific logic, identify the current OS with
process.platform
.