[Distutils] --prefix

P.J. Eby pje at telecommunity.com
Fri Sep 3 17:38:51 CEST 2010

At 10:03 AM 9/3/2010 +0100, Nick Leaton wrote:
>How can I get access to the value of --prefix from code during an install?

If you mean from setup.py, you can't.  You would need to subclass one 
of the distutils commands and ue the cmdclass argument to 
setup().  (sys.prefix is the wrong answer, by the way; it contains 
the prefix where python was installed, *not* the prefix being installed to!)

Even then, you don't want the value of --prefix, because that doesn't 
necessarily tell you where something should be installed!  Distutils 
has multiple installation schemes, many of which don't use --prefix 
at all.  --prefix is used to calculate various paths, but those paths 
can be specified individually, without using a --prefix.

What's more, when a --root installation is taking place, putting 
things under --prefix would break bdist_rpm, bdist_wininst, 
bdist_msi, and other bdist_* commands, which are actually installing 
files to a temporary location in order to build an installation 
package, rather than "really" installing anything.

In short, you're asking the wrong question, but if you can let us 
know what it is you're planning to *do* with this information, there 
may be an easier way to go about whatever you're actually trying to accomplish.

More information about the Distutils-SIG mailing list