How to get path to Python standard library directory?

U

user

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?
 
D

Dave Angel

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?

You could look at sys.executable. However, on my Linux, it's a symlink,
so you have to dereference that to get the directory involved.
 
C

Calvin Spealman

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__)
 
M

Miki Tebeka

You can try

PYLIB = $(shell python -c 'import distutils.sysconfig; print distutils.sysconfig.get_python_lib()')

(or pack the long command line in a script).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,161
Latest member
GertrudeMa
Top