Can I locate the source tree from from within the interpreter?

Skip Montanaro skip at pobox.com
Thu Feb 13 12:51:06 EST 2003


Is there a way to locate the source tree used to build an installed Python
interpreter?  This doesn't need to be platform-independent (Unix-ish
platform is sufficient).  I've poked around sys and the output of
distutils.sysconfig.get_config_vars().  Neither seems to harbor the build
tree as an absolute path.  (There is a "srcdir" entry in the
get_config_vars() output, but it's a relative path.)  I even tried opening
sys.executable and performing the moral equivalent of the strings(1)
command, but no dice (this is on MacOSX - I'm sure MMWV on other platforms).

The goal here is to be able to edit a library reference manual section
outside the build tree, then do a test "compile" of it to dvi/ps/pdf.  I
have the shell script written to do this, but so far I've had to hard code
my particular source tree into the script.  I want to check this script into
CVS somewhere so others can use it but want to avoid hard-coding the source
directory.  If it's not possible to determine the build directory at
runtime, I'll suffer with forcing the user to set an environment variable.

Thx,

Skip





More information about the Python-list mailing list