how to get distutils' install dir on Windows from external Python?

Skip Montanaro skip at
Thu Aug 22 01:17:10 CEST 2002

Under Windows I want to discover the install directory of a version of
Python other than the one I am currently running.  For example, I have both
Python 2.2.1 and 2.1.3 installed in C:\Python22 and C:\Python21,
respectively.  Both os.popen() and commands.getouput() work fine on Linux:

    >>> os.popen("python -c 'from distutils.sysconfig import get_python_lib;print get_python_lib()'").read()
    >>> commands.getoutput("python -c 'from distutils.sysconfig import get_python_lib;print get_python_lib()'")

but if I execute that on Windows, substituting "C:\\Python22\\python.exe"
for "python", I get an empty string for the popen() case and

    '{' is not recognized as an internal or external command,
    operable program or batch file.

for the getoutput() case.  This happens whether I execute either the 2.1.3
exe or the 2.2.1 exe, running from either a 2.1.3 or 2.2.1 Idle.

Any suggestions?


Skip Montanaro
skip at

More information about the Python-list mailing list