There are two things that cause a lot of people to object to the use
of setuptools: that it changes the semantics of PYTHONPATH, making it
impossible to override packages on the command-line, and that it
doesn't work when you run "setup.py install --prefix=./some_dir".
This patch addresses the first one. Currently, if you ever allow
setuptools to write into your system directory
(e.g. /usr/lib/python2.5/site-packages) then it will install a .pth
file which changes the behavior of PYTHONPATH.
This will prevent you from over-riding the installed package with a
specific package on the command-line, such as:
PYTHONPATH=./that-version-of-Twisted/ python ./my_script.py
Many people find this behavior of setuptools objectionable [1, 2, 3,
plus personal correspondance when I did my "Why do you hate
setuptools?" survey]. Fortunately it seems possible to preserve the
precedence of PYTHONPATH modules while still having installed eggs
override installed non-eggs, as motivated in .
Sat Nov 15 11:59:32 MST 2008 zooko(a)zooko.com
* leave the PYTHONPATH dirs at the front of the sys.path
This is in accordance with
http://www.python.org/doc/2.5.2/inst/search-path.html , which says
"The PYTHONPATH variable can be set to a list of paths that will be
added to the beginning of sys.path.", and it resolves an objection
many people have which impels them to ban setuptools from systems
@@ -1364,7 +1364,7 @@
"import sys; new=sys.path[sys.__plen:];"
" del sys.path[sys.__plen:];"
- " p=getattr(sys,'__egginsert',0); sys.path[p:p]=new;"
+ " p=getattr(sys,'__egginsert',len(os.environ.get
" sys.__egginsert = p+len(new)\n"
) % data
http://allmydata.org -- Tahoe, the Least-Authority Filesystem
http://allmydata.com -- back up all your files for $10/month
I'm having issues with pkg_resources.resource_filename(). If the file is
located in a directory containing accentuated characters (like ë), the
path is wrong, it's a byte string unproperly encoded whereas it should
be a unicode...
I searched on the Python bugtracker about that issue but found
nothing... Phillip, and others, what do you think?
At 05:27 PM 3/5/2009 +0000, Fadhley Salim wrote:
>In an automated build environment I need to be able to make eggs which
>depend on non-released "testing" eggs. These are all published to a
>web-server operated by my team.
>I know that it's possible to globally change the default URLs of the
>"--find-links" easy_install option by editing the distutils.cfg file,
>however I want a fully automated process which will validate a system's
>configuration and determine if the test-egg URL have been added to the
>system. If not, I want my build process to fail with an explicit error
>Other than by directly inspecting and parsing this file, is there a
>programatic way to find which hosts have been configured in the
>distutils.cfg file? Ideally I'd like to access this information via
It's not available there. You would need to create an easy_install
command instance and inspect its find_links attribute. Something like:
ei = makeSetup().get_command_obj('easy_install')
See the 'makeSetup()' function in setuptools/tests/__init__.py for
how to do the equivalent.
(Now, if what you're really asking is, can you tell whether a
specific version of an egg is available on sys.path, you can
certainly do that by checking
pkg_resources.require('projectname').version to see if it's the
version you want.)
At 01:33 PM 2/24/2009 +0100, Tarek Ziadé wrote:
> > So, the uninstallation code should simply not remove file(s) that
> are referenced by more than one manifest in the target directory --
> a relatively simple, future-proof safeguard, that doesn't require
> any specific knowledge of "namespace packages" per se.
>Sounds good. Although, it requires scanning the files again which is
>not optimal, but the last point of this mail might be an idea to
Uninstallation isn't exactly a performance-critical activity. It's
trivial to read targetdir/*/RECORD and build up a dictionary of
file->package and package->file links; this is Python, after all. ;-)
>2009/2/24 Joachim König <him(a)online.de>:
> > An other option could be to put the egg-info dir into the package
> itself, e.g.
> > zlib/
> > __init__.py
> > egg-info/
> > PKG-INFO
> > MANIFEST
> > RECORD
> > ...
>This would require setuptools and pip to change the way they look for
More precisely, it would require pkg_resources to become ridiculously
slow, by massively increasing the number of directories that need to
be read at runtime to determine what packages are present.
>Indeed. Having an index file would make things a whole lot simpler.
For *whom*? Certainly not for system packaging tools (rpm, deb, et al).
A design goal should be to allow system packaging tools to install a
static file footprint: i.e., independent files with predefined
content, and no post-processing steps. You can't do that with a
shared file, which is why setuptools uses a .pth hack to install
namespace packages when building packages for rpm et al.
>I am wondering then if this is not an evolution of the .pth files.
>Although I find that having as many .pth file as we want is not robust.
>It make things slow down when you have too many of them.
>So, I'd be in favor of a new, unique, optimized, index file,
>with a set of functions located in pkgutil to read and write in it
>This index file could also index the namespace information,
>in order to speed up the work needed to uninstall a package that
>shares a namespace.
So, .pth files are bad... let's make more? In fact, let's make a
new thing that'll have its own, new bugs? So that we can have
uninstalls that take only 1/10th of a second instead of 1/2 a second?
The standard to beat in this area, I believe, is PEP 262. At the
very least, if you're making any major changes in direction from that
PEP, the rationale for those differences should be documented. (And
consolidated index files are explicitly rejected by that PEP, with
So I have rather casually installed a bunch of packages from PyPI using
easy_install. It now contains 23 eggs, all of which get used a bit, but
nowhere near as often as the standard lib or our internal stuff.
Unsuccessfully stat()ing in all those egg directories was really starting to
hammer our NFS server (we often start up hundreds of Python processes at a
time), so I commented out the second import line at the end which serves to
leave the eggs at the end of sys.path. Now every time I install a package I
have to quickly edit easy-install.path to remove the import line the install
I wonder though... Is there some alternate way to install stuff from PyPI
which reduces the number of directories on sys.path? Maybe some
post-processing step which takes the current set of eggs, creates a single
directory into which they are all unfolded? That single directory could
then be added to sys.path.
Am I making sense? It's late. I might well not be. If so, ask me for a
more complete explanation of the idea floating around my brain.
Skip Montanaro - skip(a)pobox.com - http://www.smontanaro.net/