PDA

View Full Version : What's the proper way to determine if a python script is running in Maya?


nessus
12-09-2010, 06:36 PM
My work environment has both maya and standalone python(python.exe), and its handy sometimes for generic scripts to know which host its running in.

Initially I thought was to test importing some maya specific lib see if it throws any exception, something like this:

try:
import maya.cmds
except ImportError:
'''not in maya'''
else:
'''in maya'''

Soon I realized our standalone python interpreter (python.exe) has all maya paths included which enable us to utilize maya functionalities externally as well, so above code will never hit the exception.

How do you guys do it? thx!

_stev_
12-09-2010, 07:03 PM
One option would be to check the executable which it's called from:


import sys, os

if os.path.basename(sys.executable) == 'maya.exe':
'''in maya'''
else:
'''not in maya'''

nessus
12-09-2010, 11:19 PM
One option would be to check the executable which it's called from:


import sys, os

if os.path.basename(sys.executable) == 'maya.exe':
'''in maya'''
else:
'''not in maya'''


Thank you!

ewerybody
12-10-2010, 05:29 PM
cool! thanks too! ;]

CGTalk Moderation
12-10-2010, 05:29 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.