Repository: Lightning-AI/torchmetrics

Issue:
DeprecationWarning: The distutils package is deprecated
## 🐛 Bug

TorchMetrics still uses distutils, but distutils is deprecated.

### To Reproduce

```console
> python3 -Wall
>>> import torchmetrics
lib/python3.11/site-packages/torchmetrics/utilities/imports.py:18: DeprecationWarning: The distutils package is deprecated and slated for removal in Python 3.12. Use setuptools or check PEP 632 for potential alternatives
  from distutils.version import LooseVersion
```

### Expected behavior

I would not expect TorchMetrics to still be using distutils.

### Environment

- TorchMetrics version: 1.1, 1.2, master (spack)
- Python & PyTorch Version: 3.11.4 & 2.0.1
- Any other relevant information such as OS: macOS 13.5.2

### Additional context

I also sometimes see a different error message from pytest:
```
DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
```
This gives one possible solution.


Discussion:
seems to be related to https://github.com/Lightning-AI/utilities/issues/119
@adamjstewart would you be interested in sending a fix/upgrade?

Resolving patch:
diff --git a/.github/assistant.py b/.github/assistant.py
--- a/.github/assistant.py
+++ b/.github/assistant.py
@@ -18,11 +18,11 @@
 import re
 import sys
 import traceback
-from distutils.version import LooseVersion
 from typing import List, Optional, Tuple, Union
 
 import fire
 import requests
+from packaging.version import parse
 from pkg_resources import parse_requirements
 
 _REQUEST_TIMEOUT = 10
@@ -80,8 +80,8 @@ def set_min_torch_by_python(fpath: str = "requirements/base.txt") -> None:
         with open(fpath) as fp:
             reqs = parse_requirements(fp.readlines())
         pkg_ver = next(p for p in reqs if p.name == "torch")
-        pt_ver = min([LooseVersion(v[1]) for v in pkg_ver.specs])
-        pt_ver = max(LooseVersion(LUT_PYTHON_TORCH[py_ver]), pt_ver)
+        pt_ver = min([parse(v[1]) for v in pkg_ver.specs])
+        pt_ver = max(parse(LUT_PYTHON_TORCH[py_ver]), pt_ver)
         with open(fpath) as fp:
             requires = fp.read()
         requires = re.sub(r"torch>=[\d\.]+", f"torch>={pt_ver}", requires)
diff --git a/src/torchmetrics/utilities/imports.py b/src/torchmetrics/utilities/imports.py
--- a/src/torchmetrics/utilities/imports.py
+++ b/src/torchmetrics/utilities/imports.py
@@ -15,13 +15,13 @@
 import operator
 import shutil
 import sys
-from distutils.version import LooseVersion
 from typing import Optional
 
 from lightning_utilities.core.imports import compare_version, package_available
+from packaging.version import Version, parse
 
 _PYTHON_VERSION = ".".join(map(str, [sys.version_info.major, sys.version_info.minor, sys.version_info.micro]))
-_PYTHON_LOWER_3_8 = LooseVersion(_PYTHON_VERSION) < LooseVersion("3.8")
+_PYTHON_LOWER_3_8 = parse(_PYTHON_VERSION) < Version("3.8")
 _TORCH_LOWER_1_12_DEV: Optional[bool] = compare_version("torch", operator.lt, "1.12.0.dev")
 _TORCH_GREATER_EQUAL_1_9: Optional[bool] = compare_version("torch", operator.ge, "1.9.0")
 _TORCH_GREATER_EQUAL_1_10: Optional[bool] = compare_version("torch", operator.ge, "1.10.0")


Test patch: