Howto courtesy of Titus Brown

Using easy_install to manage your Python packages

This is so easy that it's almost silly to write a HOWTO, but ... I didn't realize how easy it was 'til I'd done it ;).

Motivation:

I'd like to give users on this machine the ability to use multiple versions of a Python package.

Solution:

Use easy_install to install everything. easy_install will build eggs for each version of each package and allow the import of specific, distinct versions through the 'require' function.

To install easy_install, I downloaded ez_setup.py and ran it:

python ez_setup.py

This downloaded and installed setuptools.

To set up multiple versions for multiple Python versions, you can do something like this:

# install for 2.4
python2.3 ez_setup.py
mv /usr/bin/easy_install /usr/bin/easy_install2.3


# install for 2.4 python2.4 
ez_setup.py 
mv /usr/bin/easy_install 
/usr/bin/easy_install2.4

# default to 2.3 
ln -fs /usr/bin/easy_install2.3 /usr/bin/easy_install

You can now use easy_install to install all of the packages that you don't want managed by apt-get (or your package manager of choice).

To install the latest version of a package via PyPi:

easy_install package_name

e.g.

easy_install twill

will install twill 0.8.1.

To install a .tar.gz that may or may not know about setuptools, try:

wget http://darcs.idyll.org/~t/twill-latest.tar.gz
easy_install twill-latest.tar.gz

This will install the latest development version of twill.

To install a specific egg:

wget http://issola.caltech.edu/~t/dist/CherryPy-2.1.0-py2.3.egg
easy_install CherryPy-2.1.0-py2.3.egg

And, finally, you can use to install files directly from an untarred distribution or a repository:

darcs get --partial http://darcs.arstecnica.it/tailor
easy_install tailor

easy_install will go grab tailor/setup.py, grok it, and install both the library code and the scripts.

easy_install: it's that easy ;). Note that I have yet to run into any problems with using it on local files; occasionally it fails to find PyPi? packages, or does strange things while scanning random Web pages.

So what drawbacks are there to easy_install? I've only run into two problems: one is that automated tests may not work for packages installed as eggs, e.g. 'tailor test' doesn't work. The other is that 'help' apparently doesn't work, either. Neither are big problems for me, because I don't use 'help' much (emacs can browse zip/egg files just fine, and I prefer reading the source code) and I'm not developing on 'tailor'.

I'll describe using the Python API to setuptools to import only a specific version of packages in a bit; haven't found the online docs for that, otherwise I'd just link to it ;).