def _getPythonVersion(self, pythonPath, destdir, libdir):
        if pythonPath not in self.pythonVersionCache:
            try:
                stdout = self._runPythonScript(pythonPath, destdir, libdir,
                        ["import sys", "print('%d.%d' % sys.version_info[:2])"])
                self.pythonVersionCache[pythonPath] = stdout.strip()
            except (OSError, RuntimeError):
                self.warn("Unable to determine Python version directly; "
                        "guessing based on path.")
                self.pythonVersionCache[pythonPath] = self._getPythonVersionFromPath(pythonPath, destdir)
        return self.pythonVersionCache[pythonPath]