Drag&Drop Installer in Maya.

Maya expects a certain folder structure such as the module being placed inside a folder named scripts. The following is a simple example:

├── # <-- This file will be dropped into Maya's viewport.
└── scripts # <-- Expected folder by Maya.
   ├── foo # <-- Our module.
   │  ├──
   │  └──
   └ # <-- Optional file to be loaded on Maya startup.

Our can be simple drag-&-dropped into Maya's viewport to run the installation process of creating a .mod file in the Maya's modules directory with the correct path to our module.

The expected to be live next to the scripts folder since it uses the parents' directory for the contents of the .mod file. Please replace the MODULE_NAME variable with the name of your module.

from pathlib import Path
import importlib, sys, os

MODULE_NAME = "foo" # <-- The name of the module.
MOD_TEMPLATE = "{name} 1.0.1 {path}"

REPOSITORY_DIR = Path(__file__).parent
MAYA_APP_DIR = os.getenv("MAYA_APP_DIR")

def install_mod():
    """Installs the module by creating a .mod file in the Maya modules directory
    with the parent's directory as the path."""

    target_mod_filepath = Path(MAYA_APP_DIR, "modules", f"{MODULE_NAME}.mod")
    target_mod_filepath.parent.mkdir(parents=True, exist_ok=True)

    mod_contents = MOD_TEMPLATE.format(name=MODULE_NAME, path=REPOSITORY_DIR.as_posix())

def load_user_setup():
    """Adds the module to the sys.path and imports the file (if it
    exists) manually for the current session. On the next startup, these will be
    loaded automatically."""

    scripts_dir = REPOSITORY_DIR.joinpath("scripts")
    user_setup = scripts_dir.joinpath("")

    if scripts_dir.exists():
        if scripts_dir not in sys.path:

        if user_setup.exists():
            spec = importlib.util.spec_from_file_location(user_setup.stem, user_setup.as_posix())
            module = importlib.util.module_from_spec(spec)

def onMayaDroppedPythonFile(*args, **kwargs):
    """Callback function to be executed when a Python file is dropped into the Maya
    viewport. It reloads the current module, installs the module, and loads the file."""

    self_import = importlib.import_module(__name__)


The file is optional and can be used to load any custom setup code when Maya starts up. It is placed in the scripts directory for Maya to be able to find it.

from maya import utils

def initialize():