DeaD_EyE

find python interpreters

Oct 26th, 2020
879
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import platform
  2. import os
  3. from pathlib import Path
  4. from subprocess import run
  5. from pprint import pprint
  6.  
  7.  
  8. os_name = platform.system().lower()
  9. if  os_name == "windows":
  10.     global_python_27_versions = [py / "python.exe" for py in Path("C:\\").glob("Python*")]
  11.     local_python_versions = [py / "python.exe" for py in (Path(os.environ["LOCALAPPDATA"]) / "Programs/Python").glob("Python*")]
  12.     known_paths = [*global_python_27_versions, *local_python_versions]
  13. elif os_name == "linux":
  14.     known_paths = ["/usr/bin", "/usr/local/bin", ".local/bin"]
  15.  
  16.  
  17. places = (Path(p) for p in known_paths)
  18.  
  19. interpreters = []
  20. for place in places:
  21.     if place.is_file():
  22.         interpreters.append(place)
  23.         continue
  24.     for binary in place.glob("python*"):
  25.         if binary.is_symlink():
  26.             continue
  27.         interpreters.append(binary)
  28.  
  29.  
  30. print("Gefundene Python-Interpreter")
  31. options = ["-c", "import sysconfig; print(sysconfig.get_paths())"]
  32. for interpreter in interpreters:
  33.     cmd = [interpreter, *options]
  34.     proc = run(cmd, capture_output=True)
  35.     print(interpreter.name)
  36.     pprint(eval(proc.stdout), indent=4, compact=True)
  37.     print("\n")
  38.  
RAW Paste Data