diff --git a/python/nx-cugraph/_nx_cugraph/__init__.py b/python/nx-cugraph/_nx_cugraph/__init__.py index d18fc53b88c..f58a6e2293b 100644 --- a/python/nx-cugraph/_nx_cugraph/__init__.py +++ b/python/nx-cugraph/_nx_cugraph/__init__.py @@ -296,6 +296,27 @@ def get_info(): return d +def _check_networkx_version(): + import warnings + + import networkx as nx + + version_major, version_minor = nx.__version__.split(".")[:2] + if version_major != "3": + warnings.warn( + f"nx-cugraph version {__version__} is only known to work with networkx " + f"versions 3.x, but networkx {nx.__version__} is installed. " + "Perhaps try upgrading your Python environment.", + UserWarning, + stacklevel=2, + ) + if len(version_minor) > 1: + raise RuntimeWarning( + f"nx-cugraph version {__version__} does not work with networkx version " + f"{nx.__version__}. Please upgrade (or fix) your Python environment." + ) + + if __name__ == "__main__": from pathlib import Path diff --git a/python/nx-cugraph/nx_cugraph/__init__.py b/python/nx-cugraph/nx_cugraph/__init__.py index 7d6a2fbe4c6..542256fa781 100644 --- a/python/nx-cugraph/nx_cugraph/__init__.py +++ b/python/nx-cugraph/nx_cugraph/__init__.py @@ -33,3 +33,6 @@ from .algorithms import * from _nx_cugraph._version import __git_commit__, __version__ +from _nx_cugraph import _check_networkx_version + +_check_networkx_version()