Installing Python modules with easy_install

I have been spending some of my spare time reading Learning Python, and experimenting with a number of Python modules. One of the cool things about the Python modules facility is easy_install, which allows you to install modules from local files or a remote location. To install a module from a local directory, you can pass the name of the module to easy_install:

$ easy_install simplejson-2.0.9
Processing
Running setup.py -q bdist_egg –dist-dir /Users/matty/simplejson-2.0.9/egg-dist-tmp-vNeFam
unable to execute gcc: No such file or directory
***************************************************************************
WARNING: The C extension could not be compiled, speedups are not enabled.
Failure information, if any, is above.
I’m retrying the build without the C extension now.
***************************************************************************
***************************************************************************
WARNING: The C extension could not be compiled, speedups are not enabled.
Plain-Python installation succeeded.
***************************************************************************
Adding simplejson 2.0.9 to easy-install.pth file

Installed /Library/Python/2.5/site-packages/simplejson-2.0.9-py2.5.egg
Processing dependencies for simplejson==2.0.9
Finished processing dependencies for simplejson==2.0.9

To install from a network location, you can pass a URL with the location of the module to easy_install:

$ easy_install http://pyyaml.org/download/pyyaml/PyYAML-3.08.tar.gz
Downloading http://pyyaml.org/download/pyyaml/PyYAML-3.08.tar.gz
Processing PyYAML-3.08.tar.gz
Running PyYAML-3.08/setup.py -q bdist_egg –dist-dir /var/folders/-a/-aYP7CaPEk00kLo-WDtJ9U+++TI/-Tmp-/easy_install-3IzAQN/PyYAML-3.08/egg-dist-tmp-5VIWBq
unable to execute gcc: No such file or directory

libyaml is not found or a compiler error: forcing –without-libyaml
(if libyaml is installed correctly, you may need to
specify the option –include-dirs or uncomment and
modify the parameter include_dirs in setup.cfg)
zip_safe flag not set; analyzing archive contents…
Adding PyYAML 3.08 to easy-install.pth file

Installed /Library/Python/2.5/site-packages/PyYAML-3.08-py2.5-macosx-10.5-i386.egg
Processing dependencies for PyYAML==3.08
Finished processing dependencies for PyYAML==3.08

You can also pass the name of a module to easy_install:

$ easy_install pexpect
Searching for pexpect
Reading http://pypi.python.org/simple/pexpect/
Reading http://pexpect.sourceforge.net/
Reading http://sourceforge.net/project/showfiles.php?group_id=59762
Best match: pexpect 2.4
Downloading http://pypi.python.org/packages/source/p/pexpect/pexpect-2.4.tar.gz#md5=fe82d69be19ec96d3a6650af947d5665
Processing pexpect-2.4.tar.gz
Running pexpect-2.4/setup.py -q bdist_egg –dist-dir /tmp/easy_install-3b5oOV/pexpect-2.4/egg-dist-tmp-aYlhyn
zip_safe flag not set; analyzing archive contents…
Adding pexpect 2.4 to easy-install.pth file

Installed /Library/Python/2.5/site-packages/pexpect-2.4-py2.5.egg
Processing dependencies for pexpect
Finished processing dependencies for pexpect

Which will cause easy_install to search the Python package index, and install the module based on information in the package index. I loves me some Python!

3 thoughts on “Installing Python modules with easy_install”

  1. While easy_install certainly looks easy, one of my concerns would be long-term maintainability.

    It’s puts stuff in /site-packages/, but if you want to upgrade, what happens when you want to move to Python 2.6 (perhaps in Mac OS 10.6?)? Or if you want to upgrade to a version of pexpect?

    Do Fink, MacPorts, or pkgsrc have the Python modules you need? Because while the above may work, IMHO it’s the equivalent of DIY compiling from tarballs: it works, and isn’t too hard, but can get very messy, very quickly if you’re not careful. A one-off here, and a one-off there, and soon you’re into the system management equivalent of spaghetti code. :)

  2. There are several things you can do to ensure maintainability in python projects.

    Probably the most important tip is to use virtualenv (http://pypi.python.org/pypi/virtualenv). This allow you to use as many python installations as you need with ease. Using virtualenv you can use easy_install or pip inside every python installation, just activacting or deactivating it.

    Second one is to use pip (http://pip.openplans.org/) as in ”’pip install –requirement src/pinax/requirements/external_apps.txt where external_apps.txt”’ has one package to be installed per line with the correct version where needed. This makes easy to re-install all the packages you need in a different virtualen. Pip install from sources, not from eggs at this time but it do all the work (download, decompress, compile, and install) for
    you.

    Pinaxproject use both and provides several examples of how to do it. http://pinaxproject.com/docs/dev/install.html

Leave a Reply

Your email address will not be published. Required fields are marked *