Add arbitrary paths to the Maya Python environment in the
userSetup.py is a Python file (not a module) which gets automatically executed on Maya startup.
userSetup.py can live in a number of locations, depending on the os and environment variables.
When Maya starts, it will execute the contents of the userSetup file. Adding Python paths here will allow it to find modules:
import sys sys.path.append("/path/to/my/modules")
This will make Python module files in '/path/to/my/modules' available for import using the standard
For more advanced setups, the
site module can do the same using the
site.addsitedir() supports .pth files which configures multiple paths in one go.
For example, three folders of unrelated Python could be arranged like this:
python_files | +---- studio | + module1.py | + module2.py | +---- external | +---- paid | + paidmodule.py | +---- foss + freemodule.py
sys.path directly you'd have to add
python_files/external/paid manually. However you could add a .pth file to the root of
python_files that looked like this:
studio external/paid external/foss
and call this in userSetup:
import site site.addsitedir("/path/to/python_files")
and you'll get all of the paths in one go.