# -*- coding: utf-8 -*- """ Created on Sun Aug 16 16:51:33 2026 @author: muhuri """ ''' Revised Python Installation and Environment Audit Report Script The script below includes the new sections: - ACTIVE PYTHON DETAILS - ANACONDA INSTALLATION CHECK ''' import os import sys import subprocess from pathlib import Path from contextlib import redirect_stdout from datetime import datetime # ------------------------------------------------------------ # Output file # ------------------------------------------------------------ output_file = r"C:\Explore\Python\PythonInstallationAuditReport.txt" # ------------------------------------------------------------ # Helper Function # ------------------------------------------------------------ def print_header(title): print("\n" + "=" * 70) print(title) print("=" * 70) # ------------------------------------------------------------ # Write Report # ------------------------------------------------------------ with open(output_file, "w", encoding="utf-8") as f: with redirect_stdout(f): print_header("PYTHON INSTALLATION AND ENVIRONMENT AUDIT REPORT") print(f"Report Generated : {datetime.now():%Y-%m-%d %H:%M:%S}") print_header("CURRENT PYTHON INTERPRETER") print(f"Python Version : {sys.version}") print(f"Executable : {sys.executable}") print(f"Prefix : {sys.prefix}") print(f"Base Prefix : {sys.base_prefix}") print(f"Platform : {sys.platform}") if sys.prefix != sys.base_prefix: print("Environment : Virtual Environment") else: print("Environment : Base Installation") print_header("PYTHON-RELATED PATH ENTRIES") path_entries = os.environ.get("PATH", "").split(os.pathsep) for entry in path_entries: if "python" in entry.lower() or "conda" in entry.lower(): print(entry) print_header("PYTHON ENVIRONMENT VARIABLES") found = False for key, value in sorted(os.environ.items()): if key.startswith("PYTHON") or "CONDA" in key: print(f"{key} = {value}") found = True if not found: print("None") print_header("WHERE PYTHON") try: result = subprocess.run( ["where", "python"], capture_output=True, text=True, timeout=10 ) print(f"Return Code: {result.returncode}") if result.stdout.strip(): print(result.stdout) else: print("No Python executable found on PATH.") if result.stderr.strip(): print("\\nSTDERR:") print(result.stderr) except Exception as e: print(f"Error: {e}") print_header("WHERE CONDA") try: result = subprocess.run( ["where", "conda"], capture_output=True, text=True, timeout=10 ) print(f"Return Code: {result.returncode}") if result.stdout.strip(): print(result.stdout) else: print("No conda executable found on PATH.") if result.stderr.strip(): print() print("STDERR:") print(result.stderr) except Exception as e: print(f"Error: {e}") # ------------------------------------------------------------ # ACTIVE PYTHON DETAILS # ------------------------------------------------------------ print_header("ACTIVE PYTHON DETAILS") print(f"Executable : {sys.executable}") if "anaconda3" in sys.executable.lower(): print("Python Type: Anaconda") else: print("Python Type: Non-Anaconda") # ------------------------------------------------------------ # ANACONDA INSTALLATION CHECK # ------------------------------------------------------------ print_header("ANACONDA INSTALLATION CHECK") anaconda_locations = [ Path.home() / "AppData/Local/anaconda3", ] for loc in anaconda_locations: print() print(loc) print(f"Exists : {loc.exists()}") print(f"python.exe : {(loc / 'python.exe').exists()}") print(f"conda.exe : {(loc / 'Scripts' / 'conda.exe').exists()}") print_header("CONDA LOCATION CHECK") possible_conda = [ Path.home() / "AppData/Local/anaconda3/Scripts/conda.exe", Path.home() / "AppData/Local/anaconda3/condabin/conda.bat", ] for p in possible_conda: print(p) print(f"Exists: {p.exists()}") print() print_header("CONDA ENVIRONMENT VARIABLES") found = False for key, value in sorted(os.environ.items()): if "CONDA" in key: print(f"{key} = {value}") found = True if not found: print("None") print_header("SUMMARY") print(f"Current Python : {sys.executable}") print(f"Current Working Directory : {os.getcwd()}") if "CONDA_DEFAULT_ENV" in os.environ: print(f"Active Conda Environment : {os.environ['CONDA_DEFAULT_ENV']}") print() print("Inspection complete.") print(f"Results written to: {output_file}")