userSetup.py in PYTHONPATH not executed

I have a Maya.env file with this line:
PYTHONPATH=/Users/myuser/blabla/something/maya

…and a userSetup.py file on that path.

In Maya I can see that /Users/myuser/blabla/something/maya has been added just fine - she reads the Maya.env file and appends the path (see below):

import sys
print(sys.path)

import os
print(os.environ[“PYTHONPATH”])

…both of these say that my path is added, but even though this is the case my userSetup.py is not executed at all during Maya startup.

The only thing I have atm in the userSetup.py is some prints and a pymel.core.cube() call. When I start up Maya I see no output in the script editor and no cube is created - my code simply doesn’t run.

What is going on?

Not sure what the problem can be from your description.
But this might help you debug the problem better.

The code that executes all of the userSetup.py files can be edited.
C:\Program Files\Autodesk\Maya2018\Python\Lib\site-packages\maya\app\startup\basic.py

from maya.app.startup import basic
basic.executeUserSetup()

Adding some prints in there might bring you a step closer to finding the issue.

2 Likes

I migrated the code in userSetup.py to userSetup.mel and it runs just fine now.
There is something odd going on about the Python version of this file - and by odd I mean something regarding Maya’s startup behavior.

One thing to watch out for with userSetup.mel is that Maya only runs the first file with that name that it finds. Whereas it will run all the userSetup.py files that exist on sys.path during startup.

One thing to try when using userSetup.py is wrapping all of your code into a function, and the calling it with maya.utils.executeDeferred(func) as sometimes the fact that userSetup.py is run so much earlier can have an impact on the results of the script.

I also noticed that the userSetup.py file for me printed in the Output Window, and not in the script editor. Took me ages to realise that it was actually picking it up :stuck_out_tongue:

Yeah, this is because at the time that it is being executed the script editor doesn’t actually exist. So stdout hasn’t been redirected to the script editor yet.

1 Like