Launch mayapy.exe with environment variables

Hi there

For an automated process, I want to launch maya.exe with a script to execute at launch, using

maya.exe -hideConsole -command mel_command

I was thinking about creating a subprocess.Popen command with some env vars, which will itself call maya.exe but it seems pretty hacky, …
Is there a way to pass environment variables to this maya session? I can’t find anything in the doc


calling subprocess with a specific environment works just fine.
otherwise you can modify the "MAYA.ENV’ file that lives in your “My Documents/Maya” folder to contain the environment variables you want, and those should be inherited by each Maya session.

the MayaPyManager (which has not been updated for py3, if that matters) will do this for you

Thanks for your answers

@Theodox is it possible to use GUI with mayapy? I need to export playblasts.

While you can use a standalone GUI library like PyQt/PySide from mayapy, you don’t get access to the normal maya GUI.
For something like playblasts, you’d need to handle that in a normal maya process.

1 Like

Got it, thanks!

I’ll do a quick try with render.exe using viewport 2.0, first then test it out using maya.exe with subprocess.Popen