[Distutils] Not repeating requirements for eggs
Phillip J. Eby
pje at telecommunity.com
Thu Jul 28 21:21:00 CEST 2005
At 02:24 PM 7/28/2005 -0400, Kevin Dangoor wrote:
>setuptools lets you declare install_requires with a set of packages.
>This is handy and is nicer than the "old way".
>In one of my __init__.py files, I am redeclaring my requirements using
>pkg_resources.require, to ensure that they're all still available and
>to load them properly.
You can shortcut this by simply require('MyProjectName'), if you've
declared the dependencies already. No point in duplication. You can also
do require('MyProjectName[somefeature]') before some operation that needs
stuff declared in extras_require.
>Does it make sense to run pkg_resources.require at runtime? (I think
Not much, actually. If you use easy_install to install a package and
aren't using --multi-version or a custom install directory, it ensures that
the package and all its dependencies are installed and active on
sys.path. So, no require()'s needed in that case. Conversely, if you
install --multi-version, then somebody will have to require() your package
to get it on sys.path, in which case all your declared dependencies will be
Finally, any scripts for eggs that use yours, or scripts from your egg,
will do all of this stuff automatically if they were installed with
So, the answer is really that explicit require() really shouldn't be
needed, if everything's an egg or you're installing to a "site" directory
(one where Python reads .pth files). If you have non-egg code involved in
importing stuff and you're not using a "site" directory, then the *non-egg*
code may need to use require().
>If so, it seems like a function could be added to pkg_resources
>that goes through this egg's required dependencies and does a
>require() on them. Something like
>What do you think?
I think it's called pkg_resources.require("MyProjectName"), and what's
more, you probably don't need to use it. :)
More information about the Distutils-SIG