Linux application deployment

P at draigBrady.com P at draigBrady.com
Mon Sep 6 12:49:39 EDT 2004


Alex Martelli wrote:
> Robert M. Emmons <RobMEmmons at cs.com> wrote:
>    ...
> 
>>One thing I've always wonders was -- Is there a way for a python module
>>to tell where it's file is located???  If you could do this it might 
> 
> 
> Piece of cake: the key part of this recipe is
>     def whereami(): return sys.modules[__name__].__file__
> then you can os.path.abspath this filename string as you wish.

That only seems to work for python 2.3 or later

One thing to consider when wondering where to put system wide
modules is that you have to worry about the python version
changing underneath you. This is because *.py[oc]
are not compatibile across minor version changes.

I.E. if one has pyc files in /usr/lib/site-python
and python 2.3 is installed subsequently on the system
then the modules probably will cause problems.

That is why py[co] files are installed in
version specific directories like:
/usr/lib/python2.2/site-packages/app/

Pádraig.



More information about the Python-list mailing list