Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import platform
- import os
- from pathlib import Path
- from subprocess import run
- from pprint import pprint
- os_name = platform.system().lower()
- if os_name == "windows":
- global_python_27_versions = [py / "python.exe" for py in Path("C:\\").glob("Python*")]
- local_python_versions = [py / "python.exe" for py in (Path(os.environ["LOCALAPPDATA"]) / "Programs/Python").glob("Python*")]
- known_paths = [*global_python_27_versions, *local_python_versions]
- elif os_name == "linux":
- known_paths = ["/usr/bin", "/usr/local/bin", ".local/bin"]
- places = (Path(p) for p in known_paths)
- interpreters = []
- for place in places:
- if place.is_file():
- interpreters.append(place)
- continue
- for binary in place.glob("python*"):
- if binary.is_symlink():
- continue
- interpreters.append(binary)
- print("Gefundene Python-Interpreter")
- options = ["-c", "import sysconfig; print(sysconfig.get_paths())"]
- for interpreter in interpreters:
- cmd = [interpreter, *options]
- proc = run(cmd, capture_output=True)
- print(interpreter.name)
- pprint(eval(proc.stdout), indent=4, compact=True)
- print("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement