diff --git a/synapse/_pydantic_compat.py b/synapse/_pydantic_compat.py index 2318fa74d427..b600c502fc5d 100644 --- a/synapse/_pydantic_compat.py +++ b/synapse/_pydantic_compat.py @@ -1,5 +1,11 @@ from packaging.version import Version -from pydantic import __version__ as pydantic_version + +try: + from pydantic import __version__ as pydantic_version +except ImportError: + import importlib.metadata + + pydantic_version = importlib.metadata.version("pydantic") HAS_PYDANTIC_V2: bool = Version(pydantic_version).major == 2