Libraries in python

Daniel 4daniel at gmail.com
Sat Sep 2 15:52:58 EDT 2006


eduardo.rosa at gmail.com wrote:
> Hy people, I'm new in python and comming from JAVA.
>
> Something I really like in java is the easy way to add a library to the
> project. Just put the jar file in the folder ( WEB-INF/lib ) and
> doesn't need to restart the server ( tomcat ).
>
> Can I do some like using python - I'm using apache mod_python?

I know exactly what you mean because I had the same question when I
came to Python from Java. What you're looking for is Python "eggs".
Unfortunately, they're a fairly new addition to the Python ecosystem
and they're not as nice/simple to use as jars. Here are a few of their
shortcomings:

1. not nearly all of the libraries that you may want to use are
distributed as eggs, so you may need to package them yourself, which
can be a pain. To be fair, this is not a shortcoming of eggs directly,
but rather a disadvantage of new technology--it's not ubiquitous yet.

2. you have to put them in the source root directory of the project so
they can be imported in all packages in the project. This seems to
clutter things up for me, and I'd rather have a project-local lib
directory in which to put them (I know that's possible with sys.path
hacks, but that's a hack, this should be standardized).

3. eggs only work well for python-only packages. In other words if the
library includes platform-specific binaries or other non-python-code
files then the egg must be unpacked for it to work. I really hate this
one because it means all those unpackaged files must be checked into
source control rather than just a single library archive file.

4. the seemingly "standard" place to deploy eggs is in the global
site-packages directory of your Python installation. That's terrible
because it makes it a pain to use different versions of a given package
in different projects. Yes, you can use the "setuptools.requires()"
function, but I want to deploy my apps without requiring those who
install it to download lots of dependencies to get it running (not to
mention I just want to use Python's standard "import", not some
non-standard "requires()" function). And yes, I know "requires()" is
supposed to automatically handle the dependencies too, but that just
seems too error prone because it makes too many assumptions about
resource availablitiy... all I want to do is bundle the library when I
deploy (preferably in the form of a single file).

That's my $0.02 on Python packaging and library dependencies. In my
opinion it's one of the few things that Java got right that Python
didn't.

~ Daniel




More information about the Python-list mailing list