3

How can I find my Mac OS X build number? And if possible, is there a way to find it using Python? I would like to use Python so that I can automatically make OS X .app files in an automated fashion.

EDIT: I see the 'Marked as duplicate' messages, and realize that people think that I mean the Mac OS X VERSION number. I'm talking about the BUILD number.

andrew
  • 448
  • 7
  • 13

4 Answers4

3

Oddly enough, the OS X build number does not seem to be available through the platform module. OS X does provide a sw_vers command which can be used to retrieve the build number through os.popen.

Example:

import os
print(os.popen("sw_vers -buildVersion").read().strip())

Output on OS X 10.9.4 Mavericks:

13E28

Not ideal, but it works!

Alexander O'Mara
  • 58,688
  • 18
  • 163
  • 171
1

Try the platform module? It will get you just about everything Python knows about the version of the OS, as well as info about the Python interpreter itself.

https://docs.python.org/2/library/platform.htm

William McBrine
  • 2,166
  • 11
  • 7
1

See https://stackoverflow.com/a/11697362/871119

A Python version might look like:

import ctypes

libc = ctypes.CDLL("libc.dylib")
size = ctypes.c_uint(256)
buf = ctypes.create_string_buffer(size.value)

if libc.sysctlbyname("kern.osversion", buf, ctypes.byref(size), None, 0) == 0:
    print buf.value
else:
    print "Fails"

Works on the system provided version of Python on my Mac.

Community
  • 1
  • 1
Zorg
  • 978
  • 6
  • 10
0

To find the current working platform, I would usually use the

    sys

module, with a .platform to get this code

    import sys
    sys.platform
'win32'
Hanson
  • 193
  • 2
  • 10