@@ -88,6 +88,14 @@ def load_cython_ext(mjpro_path):
88
88
89
89
with LockFile (lockpath ):
90
90
mod = None
91
+ force_rebuild = os .environ .get ('MUJOCO_PY_FORCE_REBUILD' )
92
+ if force_rebuild :
93
+ # Try to remove the old file, ignore errors if it doesn't exist
94
+ print ("Removing old mujoco_py cext" , cext_so_path )
95
+ try :
96
+ os .remove (cext_so_path )
97
+ except OSError :
98
+ pass
91
99
if exists (cext_so_path ):
92
100
try :
93
101
mod = load_dynamic_ext ('cymj' , cext_so_path )
@@ -98,6 +106,7 @@ def load_cython_ext(mjpro_path):
98
106
mod = load_dynamic_ext ('cymj' , cext_so_path )
99
107
return mod
100
108
109
+
101
110
def _ensure_set_env_var (var_name , lib_path ):
102
111
paths = os .environ .get (var_name , "" ).split (":" )
103
112
paths = [os .path .abspath (path ) for path in paths ]
@@ -108,6 +117,7 @@ def _ensure_set_env_var(var_name, lib_path):
108
117
"export %s=$%s:%s" % (var_name , os .environ .get (var_name , "" ),
109
118
var_name , var_name , lib_path ))
110
119
120
+
111
121
def load_dynamic_ext (name , path ):
112
122
''' Load compiled shared object and return as python module. '''
113
123
loader = ExtensionFileLoader (name , path )
@@ -236,9 +246,8 @@ def _build_impl(self):
236
246
237
247
def get_so_file_path (self ):
238
248
dir_path = abspath (dirname (__file__ ))
239
-
240
249
python_version = str (sys .version_info .major ) + str (sys .version_info .minor )
241
- return join (dir_path , "generated" , "cymj_%s .so" % self .version )
250
+ return join (dir_path , "generated" , "cymj_{}_{} .so" . format ( self .version , python_version ) )
242
251
243
252
244
253
class WindowsExtensionBuilder (MujocoExtensionBuilder ):
@@ -259,7 +268,6 @@ def __init__(self, mjpro_path):
259
268
self .extension .libraries .extend (['glewosmesa' , 'OSMesa' , 'GL' ])
260
269
self .extension .runtime_library_dirs = [join (mjpro_path , 'bin' )]
261
270
262
-
263
271
def _build_impl (self ):
264
272
so_file_path = super ()._build_impl ()
265
273
# Removes absolute paths to libraries. Allows for dynamic loading.
@@ -298,22 +306,27 @@ def __init__(self, mjpro_path):
298
306
self .extension .runtime_library_dirs = [join (mjpro_path , 'bin' )]
299
307
300
308
def _build_impl (self ):
301
- # Prefer GCC 6 for now since GCC 7 may behave differently.
302
- c_compilers = ['/usr/local/bin/gcc-6' , '/usr/local/bin/gcc-7' ]
303
- available_c_compiler = None
304
- for c_compiler in c_compilers :
305
- if distutils .spawn .find_executable (c_compiler ) is not None :
306
- available_c_compiler = c_compiler
307
- break
308
- if available_c_compiler is None :
309
- raise RuntimeError (
310
- 'Could not find GCC 6 or GCC 7 executable.\n \n '
311
- 'HINT: On OS X, install GCC 6 with '
312
- '`brew install gcc --without-multilib`.' )
313
- os .environ ['CC' ] = available_c_compiler
314
-
315
- so_file_path = super ()._build_impl ()
316
- del os .environ ['CC' ]
309
+ if not os .environ .get ('CC' ):
310
+ # Known-working versions of GCC on mac
311
+ c_compilers = ['/usr/local/bin/gcc-6' ,
312
+ '/usr/local/bin/gcc-7' ,
313
+ '/usr/local/bin/gcc-8' ]
314
+ available_c_compiler = None
315
+ for c_compiler in c_compilers :
316
+ if distutils .spawn .find_executable (c_compiler ) is not None :
317
+ available_c_compiler = c_compiler
318
+ break
319
+ if available_c_compiler is None :
320
+ raise RuntimeError (
321
+ 'Could not find GCC executable.\n \n '
322
+ 'HINT: On OS X, install GCC with '
323
+ '`brew install gcc`.' )
324
+ os .environ ['CC' ] = available_c_compiler
325
+
326
+ so_file_path = super ()._build_impl ()
327
+ del os .environ ['CC' ]
328
+ else : # User-directed c compiler
329
+ so_file_path = super ()._build_impl ()
317
330
return manually_link_libraries (self .mjpro_path , so_file_path )
318
331
319
332
@@ -469,9 +482,30 @@ def build_callback_fn(function_string, userdata_names=[]):
469
482
build_fn_cleanup (name )
470
483
return module .lib .__fun
471
484
485
+
486
+ MISSING_KEY_MESSAGE = '''
487
+ You appear to be missing a License Key for mujoco. We expected to find the
488
+ file here: {}
489
+
490
+ You can get licenses at this page:
491
+
492
+ https://www.roboti.us/license.html
493
+
494
+ If python tries to activate an invalid license, the process will exit.
495
+ '''
496
+
497
+
498
+ def find_key ():
499
+ ''' Try to find the key file, if missing, print out a big message '''
500
+ if exists (key_path ):
501
+ return
502
+ print (MISSING_KEY_MESSAGE .format (key_path ), file = sys .stderr )
503
+
504
+
472
505
def activate ():
473
506
functions .mj_activate (key_path )
474
507
508
+
475
509
mjpro_path , key_path = discover_mujoco ()
476
510
cymj = load_cython_ext (mjpro_path )
477
511
0 commit comments