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

Skip Montanaro skip at pobox.com
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()
    '/usr/local/lib/python2.3/site-packages\n'
    >>> commands.getoutput("python -c 'from distutils.sysconfig import get_python_lib;print get_python_lib()'")
    '/usr/local/lib/python2.3/site-packages'

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?

Thx,

-- 
Skip Montanaro
skip at pobox.com
consulting: http://manatee.mojam.com/~skip/resume.html




More information about the Python-list mailing list