Python : Problem running mayapy via subprocess.Popen

Here is my deal. I am initializing my python environment in userSetup.py. I am also running mayapy to batch process export files. When I run Maya normally and attempt to import my packages it works fine. However, when I use subprocess.Popen to run mayapy it doesn’t seem to import my entire package. Following is the output of a dir() of the module in both instances:

Maya normal startup:
DB : <module ‘<<<module>>>’ from ‘<<<path>>>’> > [‘AssetDB’, ‘builtins’, ‘doc’, ‘file’, ‘name’, ‘package’, ‘dirtyAssets’, ‘generateAssetDB’, ‘generateAssetFileList’, ‘generateAssetObjects’, ‘inspect’, ‘loadAssetDB’, ‘os’, ‘projectModule’, ‘re’, ‘shazObject’]

subprocess.Popen startup:
DB : <module ‘<<<module>>>’ from ‘<<<path>>>’> > [‘builtins’, ‘doc’, ‘file’, ‘name’, ‘package’, ‘inspect’, ‘os’, ‘re’, ‘shazObject’]

You’ll note that ‘AssetDB’, ‘dirtyAssets’, ‘generateAssetDB’, ‘generateAssetFileList’, ‘generateAssetObjects’, ‘loadAssetDB’ are not present in the second. These are my class and methods in the module.

What am I missing here?

Here is the call I am using :
subprocess.Popen([‘mayapy’, <<<args>>>], shell=True)

-L

I was under the impression that just running mayapy didn’t actually do a full initialize of your environment. My guess is you’d need to call your userSetup manually in the script you’re passing to mayapy.

Are you using pymel? running pymel in standalone mode will do your full setup, you can verify this for yourself by putting a print statement of some sort in your userSetup.py and importing pymel in standalone mode.

Otherwise, you can try using sitecustomize to setup an environment similar to your working environment if you don’t want to go the pymel route:

27.14. site - Site-specific configuration hook

Tho it probably might be simpler to just do the setup at the top of your script too, either way would work. I have some sample code at work I can send you that might point you in a usable direction, will post it tomorrow morning.

You are correct as I understand it. To run userSetup.py I am importing pymel.core to initialize the environment when running mayapy. What’s weirding me out is that in the instance where I run base Maya my module fully loads, and when I run mayapy it only loads the base methods and the imports.

I’m just not sure why that’s happening.

I’m working around this at the moment but I don’t like not knowing why sigh

-L

Hmm…yeah that does make it a bit more interesting. Are you importing your module in userSetup or is it somewhere in the args to mayapy?

An update. It turns out that under mayapy one of my modules is failing very quietly several imports under the top level one. I am currently setting up the scaffolding to debug in eclipse using mayapy as my interperter. Wish me luck…

-L

Any progress?

I had to work around for now based on time constraints. Attaching debug to mayapy generated a TON of warning and error spew though it did run. Going to tackle this later this month when I have a bit more time to dig in and properly sort the issue out. Will report back with progress then. Thanks for checking in though.

-L

Thread bump: for people trying to run Mayapy in a subprocess, this might be useful: