Allow to get prefix of base python interpreter

Change-Id: Ia56cd2002a790e941bdb4070978116609b7d7968
This commit is contained in:
Federico Ressi 2020-03-17 14:06:19 +01:00
parent 76999d710e
commit b1815b45f8
1 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,25 @@
#!/usr/bin/env python
import argparse
import os
import sys
print(os.path.realpath(sys.prefix))
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--base",
action="store_true",
help="print Python base prefix")
args = parser.parse_args()
prefix = get_python_prefix(base=args.base)
sys.stdout.write(prefix + '\n')
def get_python_prefix(base=False):
prefix = base and getattr(sys, 'base_prefix', None) or sys.prefix
return os.path.realpath(prefix)
if __name__ == '__main__':
main()