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

Thanks

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

e class="onebox githubgist" data-onebox-src="https://gist.github.com/theodox/2c712a91155c7e1c4c15">
gist.github.com

https://gist.github.com/theodox/2c712a91155c7e1c4c15

mayaPyManager.py
'''
Exposes the MayaPyManager class, which is used to run instances of MayaPy with explict control over paths and environment variables. A Manager can run scripts, modules, or command strings in a separate MayaPy environment; results and errors are captured and returned. 

Typical uses might be:

- running unit tests
- running a copy of Maya.standalone as a headless RPC server with StandaloneRPC https://github.com/theodox/standaloneRPC
- spawning multipe copies of maya to batch process files in parallel on a multi-core machine
- do any of the above on multiple maya versions concurrently
This file has been truncated. show original

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