Feb-21-2022, 12:29 PM
try to find installed python3 versions
from subprocess import check_output import sys # find all installed python3 versions python_version = "" python_versions_list = [] versions = check_output("which -a python3", shell=True).decode() versions_list = versions.splitlines() for v in versions_list: version = check_output(f"{v} --version", shell=True).decode().rpartition(".")[0].split(" ")[1] python_versions_list.append(version) print(f"found python{version}") python_version = f'python{sys.version.split(" ")[0].rpartition(".")[0]}' print("default python3 version:", python_version)