check_sys_env.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) Opendatalab. All rights reserved.
  2. import platform
  3. from packaging import version
  4. def is_windows_environment() -> bool:
  5. return platform.system() == "Windows"
  6. # Detect if the current environment is a Mac computer
  7. def is_mac_environment() -> bool:
  8. return platform.system() == "Darwin"
  9. def is_linux_environment() -> bool:
  10. return platform.system() == "Linux"
  11. # Detect if CPU is Apple Silicon architecture
  12. def is_apple_silicon_cpu() -> bool:
  13. return platform.machine() in ["arm64", "aarch64"]
  14. # If Mac computer with Apple Silicon architecture, check if macOS version is 13.5 or above
  15. def is_mac_os_version_supported(min_version: str = "13.5") -> bool:
  16. if not is_mac_environment() or not is_apple_silicon_cpu():
  17. return False
  18. mac_version = platform.mac_ver()[0]
  19. if not mac_version:
  20. return False
  21. # print("Mac OS Version:", mac_version)
  22. return version.parse(mac_version) >= version.parse(min_version)
  23. if __name__ == "__main__":
  24. print("Is Mac Environment:", is_mac_environment())
  25. print("Is Apple Silicon CPU:", is_apple_silicon_cpu())
  26. print("Is Mac OS Version Supported (>=13.5):", is_mac_os_version_supported())