[Distutils] Buildout: How to include installed packages in sys.path?

Jim Fulton jim at zope.com
Thu Feb 11 23:48:52 CET 2010

On Thu, Feb 11, 2010 at 12:37 PM, Gustavo Narea
<gustavonarea at 2degreesnetwork.com> wrote:
> Hello.
> I've written a Buildout recipe which relies on a function defined in a
> package whose name is set in the recipe's options. That package must
> have already been installed.
> According to the documentation, I should use
> zc.buildout.easy_install:install() like this:
>    install(["mydistribution"], None)
> But if I use None, I get an exception because Buildout tries to use
> .startswith() with None. Then, if instead of None, I use
> buildout['buildout']['directory'], it tries to install the distribution
> pulling all its dependencies (ignoring the fact I set a download cache
> in ~/.buildout/default.cfg).
> I just want to make a package available in sys.path. How should I do
> that from a Buildout recipe?
> Note I really just want to add it sys.path, not get the actual
> function/module, because it's going to be used by a function called from
> my recipe, not by my recipe.

The short answer is that buildout doesn't support this. You can do it, but
with a lot of work.  As the documentation for install,
says, if the second argument is None, it will fail unless the package
is already installed.  You need to specify the place to
install to.

It might be easier to use the zc.recipe.egg recipe from your recipe:


After using that recipe to install the needed package, you'd need to use
pkg_resources APIs to load the distribution into the running process.

You might also look at the code buildout uses to load recipes.


Jim Fulton

More information about the Distutils-SIG mailing list