[Distutils] Get install prefix for module at runtime

Tarek Ziadé ziade.tarek at gmail.com
Thu Sep 17 12:55:03 CEST 2009

On Wed, Sep 16, 2009 at 5:40 PM, Wolodja Wentland
<wentland at cl.uni-heidelberg.de> wrote:
> On Tue, Sep 15, 2009 at 17:38 +0200, Wolodja Wentland wrote:
>> My question is: "How to reliably access data files from a module in
>> foo?"
>> Approach 2 - writing a build.py file at installation time
>> ---------------------------------------------------------
>> The last question made me think, that Approach 1 works for the three
>> standard installation schemes, but fails miserably if the user decides
>> to do anything fancy.
> I implemented this approach like this:

Sorry for the late reply,

> Is this a good approach? Is there anything i can do better?

The idea of providing your own install command seems good, except that I find
writing all informations in a .py overkill.

In the same way the option --record works, you can memorize
all installation locations into a simple ConfigParser-like file you
add to the files that
are installed in Python in your package.

Your code can then read the .cfg file it at execution time using
__file__ to get your

Although with this approach you have to be careful if your package is
distributed in some environments (py2exe, setuptools eggs) where you might be
located in a zipped file.

What are your target platforms ?


More information about the Distutils-SIG mailing list