maya Maya Python Paths Using Environment Variables


The Maya Python interpreter works like a regular Python intepreter, so it will use the same environment variables to find importable files as any other Python 2.6 or 2.7 installation (described in more detail in the Python documentation.

If there is no other python installation on your machine you can use the environment variables to point at the location of your Python files for Maya (if you do have another Python, changing these for Maya's sake may interfere with your other Python installation - you'd be better off using a userSetup or startup script). Set variable PYTHONPATH so it includes your search paths. If you're editing the variable to include multiple paths remember that on *NIX systems the paths are separated by colons:

  export PYTHONPATH="/usr/me/maya/shared:/usr/me/other_python"

where on Windows they are semicolons:

  setx  PYTHONPATH C:/users/me/maya;//server/shared/maya_python

Multiple configurations

One advantage of using environment variables is that you can quickly re-configure a maya install to load tools and scripts from different locations for different projects. The easiest way to do this is to set the PYTHONPATH right before launching Maya so that you inherit the necessary paths for this maya session. For example

  set PYTHONPATH=C:/users/me/maya;//server/shared/maya_python

will launch Maya (on Windows) with the paths C:/users/me/maya and //server/shared/maya_python available for use. You could launch a second copy of Maya from a new commandline using a different set command and the second Maya would use different paths.

Because it's hard for most end-users to type these kinds of things, it's a good idea to automate the process with a batch or shell file that sets the local environment variables and launches maya. note: we need examples of this for .bat and .sh files In this system you'd distribute a .bat or .sh file for each project you were supporting and your users would launch maya using those; launching maya without the bat file would revert them to the default Maya configuration without any custom scripts.