def init_system( ): """ Check if we are suited to import the maya namespace and try to set it up such we can use the maya standalone package. If running within maya or whith maya py, this is true, otherwise we have to use the MAYA_LOCATION to get this to work. """ # RUNNING WITHIN MAYA ? Then we have everything # if being launched in mayapy, we need initialization though ! binBaseName = os.path.split( sys.executable )[1].split( '.' )[0] if binBaseName[0:4].lower() == 'maya' and binBaseName[0:6].lower() != 'mayapy': return # try to setup the paths to maya accordingly locvar = 'MAYA_LOCATION' if not os.environ.has_key( locvar ): raise EnvironmentError( locvar + " was not set - it must point to the maya installation directory" ) # EXTRACT VERSION INFORMATION IF POSSIBLE ########################################## mayalocation = os.path.realpath(os.environ[locvar]) splitpos = -1 # OS X special case if mayalocation.endswith( "Contents" ): splitpos = -3 mayabasename = mayalocation.split( os.sep )[ splitpos ] # currently unused bits = 32 if mayabasename.endswith( '64' ): bits = 64 mayabasename = mayabasename.replace( "-x64", "" ) # could be mayaxxxx-x64 mayaversion = mayabasename[4:] # could be without version, like "maya" fmayaversion = float(mayaversion) # PYTHON COMPATABILITY CHECK ############################## pymayaversion = sys.version_info[0:2] if len( mayaversion ): pyminor = pymayaversion[1] if mayaversion not in [ '8.5', '2008', '2009', '2010', '2011' ]: raise EnvironmentError( "Requires Maya 8.5 or higher for python support, found " + mayaversion + ", or maya version is not implemented" ) if ( mayaversion == "8.5" and pyminor != 4 ) or \ ( mayaversion == "2008" and pyminor != 5 ) or \ ( mayaversion == "2009" and pyminor != 5 ) or \ ( mayaversion == "2010" and pyminor != 6 ) or \ ( mayaversion == "2011" and pyminor != 6 ): raise EnvironmentError( "Maya " + mayaversion + " python interpreter requirements not met" ) # END check python version # END check maya version # FINALLY INIALIZE MAYA TO TO MAKE USE OF MAYA STANDALONE ########################################################### if os.name == "nt": osspecific = os.path.join("Python", "lib") else: pyversionstr = str( pymayaversion[0] ) + "." + str( pymayaversion[1] ) osspecific = os.path.join("lib", "python" + pyversionstr, "site-packages") mayapylibpath = os.path.join( mayalocation, osspecific, "site-packages" ) sys.path.append( mayapylibpath ) # CHECK AND FIX SYSPATH ######################## # to be very sure: If for some reason we have our own root package # in the path, remove it as we would most likely import our own maya # This appears to happen if mrv is installed as site-package btw. packagename = mrv.__name__ for path in sys.path[:]: if path.endswith("/"+packagename) or path.endswith("\\"+packagename): sys.path.remove(path) # END if it is an invalid path # END for each sys path # although this was already done, do it again :). Its required if mrv is installed # natively mrv._remove_empty_syspath_entries() try: import maya except Exception, e: print "Paths in sys.path: " for p in sys.path: print "%r" % p raise EnvironmentError( "Failed to import maya - check this script or assure LD_LIBRARY path is set accordingly: " + str( e ) )
def init_system( ): """ Check if we are suited to import the maya namespace and try to set it up such we can use the maya standalone package. If running within maya or whith maya py, this is true, otherwise we have to use the MAYA_LOCATION to get this to work. """ # RUNNING WITHIN MAYA ? Then we have everything # if being launched in mayapy, we need initialization though ! binBaseName = os.path.split( sys.executable )[1].split( '.' )[0] if binBaseName[0:4].lower() == 'maya' and binBaseName[0:6].lower() != 'mayapy': return # try to setup the paths to maya accordingly locvar = 'MAYA_LOCATION' if not os.environ.has_key( locvar ): raise EnvironmentError( locvar + " was not set - it must point to the maya installation directory" ) # EXTRACT VERSION INFORMATION IF POSSIBLE ########################################## mayalocation = os.path.realpath(os.environ[locvar]) splitpos = -1 # OS X special case if mayalocation.endswith( "Contents" ): splitpos = -3 match = re.search("\d{4}", mayalocation) if match is not None: mayaversion = match.group(0) # could be without version, like "maya" fmayaversion = float(mayaversion) # PYTHON COMPATABILITY CHECK ############################## pymayaversion = sys.version_info[0:2] if len( mayaversion ): pyminor = pymayaversion[1] if float(mayaversion) not in maya_to_py_version_map: raise EnvironmentError( "Requires Maya 8.5 or higher for python support, found " + mayaversion + " (or maya version is not implemented)" ) pyversion = pymayaversion[0] + (pymayaversion[1]/10.0) if maya_to_py_version_map[float(mayaversion)] != pyversion: raise EnvironmentError( "Maya " + mayaversion + " python interpreter requirements not met" ) # END check python version # END check maya version else: # Assume the most common python version pymayaversion = (2, 6) fmayaversion = 2013.0 print "Couldn't extract maya version for mprogram '%s', assuming python version %s" % (mayalocation, '.'.join(str(i) for i in pymayaversion)) # end couldn't extract maya version, which can happen actually # CHECK AND FIX SYSPATH ######################## # to be very sure: If for some reason we have our own root package # in the path, remove it as we would most likely import our own maya # This appears to happen if mrv is installed as site-package btw. # remove existing sys-paths containing maya, just to be sure we get the right one for path in sys.path[:]: if os.path.isdir(os.path.join(path, 'maya')) and not path.endswith("site-packages"): sys.path.remove(path) # END if if maya package was found # END for each path in sys.path # FINALLY INIALIZE MAYA TO TO MAKE USE OF MAYA STANDALONE ########################################################### if os.name == "nt": osspecific = os.path.join("Python", "lib") else: pyversionstr = str( pymayaversion[0] ) + "." + str( pymayaversion[1] ) osspecific = os.path.join("lib", "python" + pyversionstr, "site-packages") mayapylibpath = os.path.join( mayalocation, osspecific, "site-packages" ) sys.path.append( mayapylibpath ) # although this was already done, do it again :). Its required if mrv is installed # natively mrv._remove_empty_syspath_entries() try: import maya except Exception, e: print "Paths in sys.path: " for p in sys.path: print "%r" % p raise EnvironmentError( "Failed to import maya - check this script or assure LD_LIBRARY path is set accordingly: " + str( e ) )
def init_system(): """ Check if we are suited to import the maya namespace and try to set it up such we can use the maya standalone package. If running within maya or whith maya py, this is true, otherwise we have to use the MAYA_LOCATION to get this to work. """ # RUNNING WITHIN MAYA ? Then we have everything # if being launched in mayapy, we need initialization though ! binBaseName = os.path.split(sys.executable)[1].split('.')[0] if binBaseName[0:4].lower( ) == 'maya' and binBaseName[0:6].lower() != 'mayapy': return # try to setup the paths to maya accordingly locvar = 'MAYA_LOCATION' if not os.environ.has_key(locvar): raise EnvironmentError( locvar + " was not set - it must point to the maya installation directory") # EXTRACT VERSION INFORMATION IF POSSIBLE ########################################## mayalocation = os.path.realpath(os.environ[locvar]) splitpos = -1 # OS X special case if mayalocation.endswith("Contents"): splitpos = -3 mayabasename = mayalocation.split(os.sep)[splitpos] # currently unused bits = 32 if mayabasename.endswith('64'): bits = 64 mayabasename = mayabasename.replace("-x64", "") # could be mayaxxxx-x64 mayaversion = mayabasename[4:] # could be without version, like "maya" fmayaversion = float(mayaversion) # PYTHON COMPATABILITY CHECK ############################## pymayaversion = sys.version_info[0:2] if len(mayaversion): pyminor = pymayaversion[1] if mayaversion not in ['8.5', '2008', '2009', '2010', '2011']: raise EnvironmentError( "Requires Maya 8.5 or higher for python support, found " + mayaversion + ", or maya version is not implemented") if ( mayaversion == "8.5" and pyminor != 4 ) or \ ( mayaversion == "2008" and pyminor != 5 ) or \ ( mayaversion == "2009" and pyminor != 5 ) or \ ( mayaversion == "2010" and pyminor != 6 ) or \ ( mayaversion == "2011" and pyminor != 6 ): raise EnvironmentError("Maya " + mayaversion + " python interpreter requirements not met") # END check python version # END check maya version # FINALLY INIALIZE MAYA TO TO MAKE USE OF MAYA STANDALONE ########################################################### if os.name == "nt": osspecific = os.path.join("Python", "lib") else: pyversionstr = str(pymayaversion[0]) + "." + str(pymayaversion[1]) osspecific = os.path.join("lib", "python" + pyversionstr, "site-packages") mayapylibpath = os.path.join(mayalocation, osspecific, "site-packages") sys.path.append(mayapylibpath) # CHECK AND FIX SYSPATH ######################## # to be very sure: If for some reason we have our own root package # in the path, remove it as we would most likely import our own maya # This appears to happen if mrv is installed as site-package btw. packagename = mrv.__name__ for path in sys.path[:]: if path.endswith("/" + packagename) or path.endswith("\\" + packagename): sys.path.remove(path) # END if it is an invalid path # END for each sys path # although this was already done, do it again :). Its required if mrv is installed # natively mrv._remove_empty_syspath_entries() try: import maya except Exception, e: print "Paths in sys.path: " for p in sys.path: print "%r" % p raise EnvironmentError( "Failed to import maya - check this script or assure LD_LIBRARY path is set accordingly: " + str(e))