Wrapping my head around an egg...

Posted on February 9th, 2009 by raoul and tagged , , , , , , , .

Perl has CPAN, Ubuntu and Debian have apt/debs, Gentoo has portage. These are all various distribution or packaging systems, which allow you to download and install packages from the various systems fairly easily. Of course Python also has it's own system.

In Python, packages are shipped as "egg" files, special zip files with information inside them to tell Python what version of Python they are for, what other packages they need, and other useful stuff. These egg files can be downloaded from the Internet and automatically installed via the easy_install command.

From the Easy Install site:

Easy Install is a python module bundled with setuptools that lets you automatically download, build, install, and manage Python packages.

Easy Install not only downloads and installs the Python package you want, it also downloads and installs any dependencies (packages that your package needs to work properly). What's more, Easy Install can also install from a local egg file, and still download the dependencies.

With the work I've been doing with Project HQ, and also having used Pylons at work, I've learned a lot about Python packaging. In the beginning, I didn't know how to use Easy Install to install my eggs, nor how it all fits together. Here are some of the things I've learnt so far:

  • You can install stuff directly from an egg file:
    easy_install MyProject-0.1-py2.5.egg
  • As long as you set your dependencies in your setup.py file, they will be downloaded and installed if necessary.
  • You can upgrade packages easily:
    easy_install --upgrade MyProject-0.1-py2.5.egg
  • Once installed, using the package in your Python applications is as simple as import PyQt4
  • It's possible to have 2 different versions of a package installed at the same time. I'm not sure how this works in using one or another version in your Python app, but I'm sure that's easy enough to do.

In short, I've been enjoying using Python, and learning about all the different utilities and things available (stuff like easy_install and paster, for instance).