by Johan Borgström
To make a folder containing Python scripts visible to Maya one way is to add the path to the folder to the Pyhon Path in the Maya.env file. It is located C:\Users\[your user name]\Documents\maya\[your maya version].
Simply add the path to the file. If you wish to add multiple folders just insert a semi colon between the paths
PYTHONPATH = D:\Projects\python
To check wich paths Maya has setup run the following Python script in the script editor.
import sys
syspaths = sys.path
for p in syspaths: print p
Module
A Module is simply a standalone Python file and can consist of how many or few lines of code as required.
Packages
One convenient way to distribute Python scripts is to use packages. To make a folder into a package add a file called __init__.py to the folder. This file does not need to contain anything but a convenient thing is to import the modules inside the folder ( or package ). Importing in the __init__.py file lets us access the “sub modules” through the package namespace. Letsuse an example to demonstrate this.
We have in our maya.env file added the path to a folder containing scripts or packages we wish to access. In the folder specified by the python path we add a folder called “petfactory” for instance. This folder contains a file called __init__.py and a python module ( script file ) named mammal.py. Below is the content of the mammal.py file.

Below is the content of the mammal.py file. For an intro to creating a python class see the post Intro to Python – How to write a class
class Pet(object):
type = 'mammal'
def __init__(self, aSpecies):
self.species = aSpecies
print('a pet %s was created' %self.species)
def speak(self, aSound):
print(aSound * 2)
Below is the content of the __init__.py file.
import mammal
So when we wish to create a Pet in Maya we enter the following in a Python tab in the script editor
import petfactory
# create a Pet instance
myPet = petfactory.mammal.Pet("Dog")
myPet.species
# Result: Dog #