How to get path to Python standard library directory?

Calvin Spealman ironfroggy at gmail.com
Fri Nov 25 08:23:33 EST 2011


On Fri, Nov 25, 2011 at 6:24 AM, user <user at nospam.invalid> wrote:
> In a Makefile (or sometimes inside python) I need the path to the root of
> the Python standard lib folder used by "env python".
>
> e.g.  /usr/lib/python2.6/   or    C:\Python27\Lib\
>
> what is the best/canonical way to get that?

This should get you what you're looking for. Just look relative to a
known stdlib module.

import os
stdlib_dir = os.path.dirname(os.__file__)

> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy



More information about the Python-list mailing list