Raise an informative error when running on macOS under Rosetta 2.

Current users only get a cryptic "Illegal instruction" crash.

Context: https://github.com/deepmind/mujoco/issues/611
PiperOrigin-RevId: 491705647
Change-Id: I1285897a36e858300ee3d125957e90754be9a7f7
This commit is contained in:
Saran Tunyasuvunakool
2022-11-29 12:17:58 -08:00
committed by Copybara-Service
parent 5f7d9f4f02
commit df25d7d602
9 changed files with 93 additions and 9 deletions
+12
View File
@@ -23,6 +23,18 @@ import subprocess
_SYSTEM = platform.system()
if _SYSTEM == 'Windows':
ctypes.WinDLL(os.path.join(os.path.dirname(__file__), 'mujoco.dll'))
elif _SYSTEM == 'Darwin':
proc_translated = subprocess.run(
['sysctl', '-n', 'sysctl.proc_translated'], capture_output=True).stdout
try:
is_rosetta = bool(int(proc_translated))
except ValueError:
is_rosetta = False
if is_rosetta and platform.machine() == 'x86_64':
raise ImportError(
'You are running an x86_64 build of Python on an Apple Silicon '
'machine. This is not supported by MuJoCo. Please install and run a '
'native, arm64 build of Python.')
from mujoco._callbacks import *
from mujoco._constants import *