How to Install SetupTools for Maya and use it to install packages

One another quicky about installing SetupTools for Maya (needs root permission):

  1. Download the SetupTools source tarball from PyPi
  2. Extract it somewhere (with "tar -xvzf setuptools-2.1.tar.gz")
  3. Run:
    sudo /usr/autodesk/maya/bin/mayapy /path/to/the/extracted/tarbar/setuptools-2.1/setup.py install
            
Now you should have easy_install at /usr/autodesk/maya/bin/ try installing something (don't forget being root):
sudo /usr/autodesk/maya/bin/easy_install sqlalchemy

Traceback (most recent call last):
  File "/usr/autodesk/maya/bin/easy_install", line 5, in 
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2797, in 
    parse_requirements(__requires__), Environment()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 576, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: setuptools==2.1
Interesting isn't it! I don't know what the problem is here, but, here is the workaround:
  1. Run mayapy as root:
    sudo /usr/autodesk/maya/bin/mayapy
            
  2. Install the package using python:
    from setuptools.command import easy_install
    easy_install.main(['sqlalchemy'])
            
Problem solved!

Rather than trying to use mayapy with root permission, I would love to be able to use virtualenv created against mayapy but for now it seems there are some path issues.

But I have an idea of creating a normal virtualenv for the system python, make it relocatable, and then replace all the paths and symlinks to mayapy. Will try that whenever I have time.

Comments