Traceback (most recent call last):
File “/scratch/AzureNfsServer_INPUT1/vc_data/users/willing/home/mQG/src/1_train.py”, line 14, in
import pytorch_lightning as pl
File “/home/aiscuser/.conda/envs/willing/lib/python3.9/site-packages/pytorch_lightning/init.py”, line 34, in
from pytorch_lightning.callbacks import Callback # noqa: E402
File “/home/aiscuser/.conda/envs/willing/lib/python3.9/site-packages/pytorch_lightning/callbacks/init.py”, line 25, in
from pytorch_lightning.callbacks.progress import ProgressBarBase, RichProgressBar, TQDMProgressBar
File “/home/aiscuser/.conda/envs/willing/lib/python3.9/site-packages/pytorch_lightning/callbacks/progress/init.py”, line 22, in
from pytorch_lightning.callbacks.progress.rich_progress import RichProgressBar # noqa: F401
File “/home/aiscuser/.conda/envs/willing/lib/python3.9/site-packages/pytorch_lightning/callbacks/progress/rich_progress.py”, line 20, in
from torchmetrics.utilities.imports import _compare_version
ImportError: cannot import name ‘_compare_version’ from ‘torchmetrics.utilities.imports’ (/home/aiscuser/.conda/envs/willing/lib/python3.9/site-packages/torchmetrics/utilities/imports.py)

There are a few possible reasons for this error:

  • The version of torchmetrics installed is incompatible with the version of pytorch_lightning. According to the pytorch_lightning documentation, the minimum required version of torchmetrics is 0.4.1. You can check your installed version with pip show torchmetrics or conda list torchmetrics and upgrade it if necessary with pip install --upgrade torchmetrics or conda update torchmetrics.
  • The installation of torchmetrics or pytorch_lightning is corrupted or incomplete. You can try reinstalling them with pip install --force-reinstall torchmetrics pytorch_lightning or conda install --force-reinstall torchmetrics pytorch_lightning.