build.rs: Handle `python` being Python 2

If `python` refers to Python 2 (as recommended in [1]) the build fails
with:
  AttributeError: 'module' object has no attribute 'base_prefix'

Since there is no `base_prefix` in Python 2, simply use `exec_prefix` if
the AttributeError is raised.

[1] https://www.python.org/dev/peps/pep-0394/
This commit is contained in:
Alexander Niederbühl 2019-05-15 23:22:24 +02:00
parent 134c129edc
commit 21a2f816fc
1 changed files with 4 additions and 1 deletions

View File

@ -503,7 +503,10 @@ if PYPY:
else:
print(sysconfig.get_config_var('Py_ENABLE_SHARED'))
print(sysconfig.get_config_var('LDVERSION') or sysconfig.get_config_var('py_version_short'))
print(sys.base_prefix)
try:
print(sys.base_prefix)
except AttributeError:
print(sys.exec_prefix)
print(platform.python_implementation())
"#;
let out = run_python_script(interpreter, script)?;