Adding path to custom Module crashes Maya 2019

I am running Maya from Python with subprocess to set the necessary environment.
If I add a PYRHONPATH to my custom package ( os.environ[‘PYTHONPATH’] =‘my/path’), Maya prints error:

cannot find procedure MTsettogglemenuitem

and does not launch.

Can you help me to troubleshoot the issue? I have no clue where is the problem (without this path maya launches normally). Also, Maya 2016 launches normally with this path.

The only option I can think of is that I have some modules/packages names that conflict with Maya. E.g. I have core, setting, database and other names…

The issue cause custom module “maya” with Maya tools an Renaming module solve the issue… but still, I don`t get whats going on (its working fine with 2016).

So if I’m understanding you basically had: my/path/ or my/path/maya/

And added /my/path to PYTHONPATH?

Yeah that makes sense that it would cause import issues, given that maya is already a top level module namespace that everything in maya relies on.

I’m actually surprised that such a setup works in 2016

Sorry I can’t troubleshoot the exact issue right now, but maybe a workaround will suffice?
Instead of the PYTHONPATH variable, maybe you can do a sys.path.append('my/path') ?
Of course, depending on the order you’re doing things it may or may not be useful to you.

1 Like

Oh wait I think I read that wrong.

Yeah, so 2018 added a bunch of new plugins / modules that totally screw with some module names.

Also you definitely don’t want to be running stock 2018, as it scrambles the import paths during startup.

I believe 2018.1 was when the fix landed.

You probably should look into namespacing your code by placing it in a package, and using relative imports internally so that these kind of conflicts are less likely to happen.

1 Like

I ended up renaming “maya” to “x_maya” and got it working.
Still sorting out all my paths trying to move all path setup to one place.