From c0e6fd6a3b90ac37b894ef45e2e72b747ea02e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20W=C3=A4lchli?= Date: Fri, 15 Apr 2022 00:33:21 +0200 Subject: [PATCH] Fix version comparison for python version in `pl.utilities.imports` (#12754) --- pytorch_lightning/utilities/imports.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pytorch_lightning/utilities/imports.py b/pytorch_lightning/utilities/imports.py index 13e467ef6e..232c51ad63 100644 --- a/pytorch_lightning/utilities/imports.py +++ b/pytorch_lightning/utilities/imports.py @@ -64,6 +64,8 @@ def _compare_version(package: str, op: Callable, version: str, use_base_version: >>> _compare_version("torch", operator.ge, "0.1") True + >>> _compare_version("does_not_exist", operator.ge, "0.0") + False """ try: pkg = importlib.import_module(package) @@ -85,7 +87,7 @@ def _compare_version(package: str, op: Callable, version: str, use_base_version: _IS_WINDOWS = platform.system() == "Windows" _IS_INTERACTIVE = hasattr(sys, "ps1") # https://stackoverflow.com/a/64523765 -_PYTHON_GREATER_EQUAL_3_8_0 = _compare_version("python", operator.ge, "3.8.0") +_PYTHON_GREATER_EQUAL_3_8_0 = Version(platform.python_version()) >= Version("3.8.0") _TORCH_GREATER_EQUAL_1_8_1 = _compare_version("torch", operator.ge, "1.8.1") _TORCH_GREATER_EQUAL_1_9 = _compare_version("torch", operator.ge, "1.9.0") _TORCH_GREATER_EQUAL_1_9_1 = _compare_version("torch", operator.ge, "1.9.1")