multiple userSetup.py files

2,347 views
Skip to first unread message

Kenneth Polonski

unread,
Jun 9, 2014, 3:03:16 PM6/9/14
to python_in...@googlegroups.com
Hey everyone,

So I've recently written a custom menu with some pipeline tools for the company I work for. Basically my workflow to load it is the following:

  1. PYTHONPATH env variable is set with maya wrapper script.
  2. sitecustomize.py file is loaded and appends my module's path to the sys.path list
  3. global userSetup.py file is read to import the modules and executeDefered is used to load the menu after maya's initialization

This all works perfectly, but the problem comes when a user's personal userSetup.(py/mel) file will not be executed.

How would it be possible for me to load the site wide userSetup.py file and still have the individual user's userSetup files be functional? I really don't know another way to load the menu without using a userSetup file so if anyone could tell me another way (or a way to get 2 userSetup files to work) that would be great!

Thanks,

Kenny

Fredrik Averpil

unread,
Jun 9, 2014, 3:44:12 PM6/9/14
to python_in...@googlegroups.com

Hi Kenneth,

I believe you should be able to use a usercustomize.py which will be loaded just after sitecustomize.py.
Also, you can load both a userSetup.mel and a userSetup.py. Mind you, userSetup.py is called later than userSetup.mel and cannot perform all commands that userSetup.mel can perform…

And from python, you can dynamically import other scripts, perhaps based off your machine names… (haven’t tried this myself)

import socket
moduleNames = [ 'sys', 'os', socket.gethostname() ] 
modules = map(__import__, moduleNames)

By the way, I’ve never gotten around reading up on how the site/usercustomize.py differs from the userSetup.py/mel – and I can’t find any documentation on sitecustomize.py … what’s the main difference?

// Fredrik

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/16f93c91-de9d-4593-b9df-fa4e8a2e8a5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jesse Kretschmer

unread,
Jun 9, 2014, 6:42:51 PM6/9/14
to python_in...@googlegroups.com
sitecustomize.py is sourced by python each time the interpreter starts up. Python will search the PYTHONPATH the first sitecustomize file found. Immediately after it will search the same set of paths for usercustomize.py. Both are meant to help you dynamically change your python environment, though you can do loads more. I can't find a good doc page, but this writeup is good: http://pymotw.com/2/site/

userSetup is only for Maya. Maya supports a single userSetup.mel file, but since python was added, it now supports multiple userSetup.py files. Maya loop over the entire sys.path and run execfile() on any userSetup.py found. Read the friendly source here: Maya2014/Python/Lib/site-packages/maya/app/startup/basic.py

On Mon, Jun 9, 2014 at 12:03 PM, Kenneth Polonski <kpol...@gmail.com> wrote:
How would it be possible for me to load the site wide userSetup.py file and still have the individual user's userSetup files be functional?

I run multiple userSetup.py files at my studio. I'm not sure why you would have issues running multiple files. I created a single studio userSetup.py, but I encourage users to create their own userSetup.py files which will get executed after the studio version which is made available via the PYTHONPATH. From the source maya will file and execute userSetup.py files in this order <user>/maya/prefs/scripts, <user>/maya/scripts, <user>/maya/<version>/scripts. 

Kenneth Polonski

unread,
Jun 10, 2014, 12:01:18 PM6/10/14
to python_in...@googlegroups.com, je...@krets.com
Thanks for the info Jesse.

I really can't explain why it's not reading the local userSetup.py file and it's actually getting quite frustrating. My personal userSetup file is located in ~/maya/2014-x64/prefs/scripts folder and my commandPorts and everything don't work at all now since it wont load it. I'll keep trying to figure this out and I'll get back on what the issue was once I figure it out.

Kenneth Polonski

unread,
Jun 10, 2014, 12:39:18 PM6/10/14
to python_in...@googlegroups.com, je...@krets.com
Alright solved it! It was one of those really stupid little things that you don't even look for and when you find it, you realize you're an idiot. I was importing pm.core instead of pymel.core in my local userSetup and obviously that was erroring out without printing any errors since maya isn't initalized yet. Yay typos.

Well thanks guys! Your help was much appreciated.

Jesse Kretschmer

unread,
Jun 10, 2014, 12:57:37 PM6/10/14
to Kenneth Polonski, python_in...@googlegroups.com

On Tue, Jun 10, 2014 at 9:39 AM, Kenneth Polonski <kpol...@gmail.com> wrote:
Yay typos.

It's always the little things. Thanks for pointing out the resolution to help the next guy that has some unknown load issue.

I'm on windows and Maya prints the traceback to the output window. I suppose on Linux/Mac it should stream it out to the shell, though I have limited experience.

Kenneth Polonski

unread,
Jun 10, 2014, 1:05:15 PM6/10/14
to python_in...@googlegroups.com, kpol...@gmail.com, je...@krets.com
Yeah I'm on Linux and it printed this to the shell:

Failed to execute userSetup.py
Traceback (most recent call last):
  File "/home/molecule/maya/2014-x64/prefs/scripts/userSetup.py", line 2, in <module>
    import pm.core as pm

Didn't even look there for some reason, but I found the error by running the for loop from basic.py after maya launched. Thanks again!
Reply all
Reply to author
Forward
0 new messages