How to tell if rosetta is installed?

Question:

I am working on a Python script that will rely on rosetta being installed. Rosetta is a dynamic binary translator for Mac OS X which allows many PowerPC applications to run on certain Intel-based Macintosh computers without modification. Is there anyway for to check the OS to see if rosetta is there?

Asked By: Mizmor

||

Answers:

Haven’t got rosetta installed anymore but if I recall correctly it would give some kind of usage screen if you just type translate (rosetta command line). If so, something like this should work.

if os.system("/usr/libexec/oah/translate > /dev/null 2>&1"):
  print "Not installed"
else:
  print "Installed"
Answered By: Maria Zverina

If you are really just trying to check whether something with a PPC dependency will likely run, you could do a loose check that the running CPU type is PPC or the running OS X version >= 10.4 and < 10.7 since those are the OS X versions where Rosetta is supported and, at least on 10.6, OS X will automatically prompt the user to install Rosetta when needed if it wasn’t already installed. Note that the Darwin kernel versions are different from the OS X version number, i.e 10.4 -> Darwin 8, 10.5 -> 9, etc.:

>>> import os
>>> os.uname()
('Darwin', 'kitt.local', '11.4.0', 'Darwin Kernel Version 11.4.0: Mon Apr  9 19:32:15 PDT 2012; root:xnu-1699.26.8~1/RELEASE_X86_64', 'x86_64')
>>> un = os.uname()
>>> darwin_major_version = int(os.uname()[2].split('.')[0])
>>> cputype = un[4]
>>> can_run_ppc = cputype.startswith('ppc') or (darwin_major_version > 7 and darwin_major_version < 11)
>>> can_run_ppc
False
Answered By: Ned Deily

There is no official way to get this.

Rosetta works via a program called /usr/libexec/oah/translate. Officially, this is an implementation detail which is subject to change, and therefore shouldn’t be relied on. However, we know that it never did change until 10.7, when Rosetta was killed completely, so it’s safe despite the caveats. Maria Zverina’s answer works for that (if you add the path), and it’s probably the simplest. Or, maybe, just check for the presence of such a file instead of running it.

Alternatively, Rosetta came with Intel 10.4-10.6 (earlier versions of the OS were PPC-only and didn’t have Intel). Again, officially you’re never supposed to rely on OS version, instead using the appropriate APIs to check for features. But in this case, there don’t seem to be any appropriate APIs, so maybe this is appropriate. Except for the caveat that you don’t have to install Rosetta with 10.6, so this won’t detect users who turned off the checkbox. If you want to do this:

import platform
release, versioninfo, machine = platform.mac_ver()
versionbits = [int(bit) for bit in release.split('.')]
rosetta = (versionbits < (10,7) and not machine.startswith('ppc'))

(Note that this is also “bad” because on some versions platform.mac_ver() does some hacky stuff that you’re not supposed to do—the right way to get the OS X version bits is to call Gestalt. But mac_ver() is part of the standard library, so at least you can rely on it doing the hacky stuff as well as possible, and it being widely tested.)

If you’re not actually after Rosetta, but whether you can run PPC either natively or via Rosetta, that’s even simpler. All pre-10.7 versions that don’t come with Rosetta are PPC; all 10.7+ versions can’t run PPC period. So, just “release < ‘10.7’” does it. (Again, with the caveat that 10.6 can optionally skip Rosetta install.)

Answered By: abarnert

Try to run:

brew config

Rosetta 2: true

enter image description here

Answered By: Quockhanh Pham