Torch_geometric.nn package gives versioning error when importing

The import:

from torch_geometric.nn import GCNConv

returns:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
~/anaconda3/envs/py38/lib/python3.8/site-packages/torch_cluster/__init__.py in <module>
     13     ]:
---> 14         torch.ops.load_library(importlib.machinery.PathFinder().find_spec(
     15             library, [osp.dirname(__file__)]).origin)

~/anaconda3/envs/py38/lib/python3.8/site-packages/torch/_ops.py in load_library(self, path)
    109             # operators with the JIT.
--> 110             ctypes.CDLL(path)
    111         self.loaded_libraries.add(path)

~/anaconda3/envs/py38/lib/python3.8/ctypes/__init__.py in __init__(self, name, mode, handle, use_errno, use_last_error, winmode)
    372         if handle is None:
--> 373             self._handle = _dlopen(self._name, mode)
    374         else:

OSError: /home/user/anaconda3/envs/py38/lib/python3.8/site-packages/torch_cluster/_version.so: undefined symbol: _ZN3c1017RegisterOperatorsD1Ev

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-5-b6dacbfe5071> in <module>
      2 import torch.nn as nn
      3 from torch.nn import CrossEntropyLoss
----> 4 from torch_geometric.nn import GCNConv #, AGNNConv,  GraphConv, TopKPooling, global_mean_pool, SAGEConv
      5 #from torch_geometric.nn import ChebConv, GATConv,  HypergraphConv,  GINConv, SGConv,  TransformerConv
      6 

~/anaconda3/envs/py38/lib/python3.8/site-packages/torch_geometric/nn/__init__.py in <module>
      3 from .sequential import Sequential
      4 from .data_parallel import DataParallel
----> 5 from .to_hetero_transformer import to_hetero
      6 from .to_hetero_with_bases_transformer import to_hetero_with_bases
      7 from .conv import *  # noqa

~/anaconda3/envs/py38/lib/python3.8/site-packages/torch_geometric/nn/to_hetero_transformer.py in <module>
      7 from torch.nn import Module
      8 
----> 9 from torch_geometric.nn.fx import Transformer
     10 from torch_geometric.typing import EdgeType, Metadata, NodeType
     11 from torch_geometric.utils.hetero import get_unused_node_types

~/anaconda3/envs/py38/lib/python3.8/site-packages/torch_geometric/nn/fx.py in <module>
      5 from torch.nn import Module, ModuleDict, ModuleList, Sequential
      6 
----> 7 from torch_geometric.nn.conv import MessagePassing
      8 
      9 try:

~/anaconda3/envs/py38/lib/python3.8/site-packages/torch_geometric/nn/conv/__init__.py in <module>
      4 from .sage_conv import SAGEConv
      5 from .graph_conv import GraphConv
----> 6 from .gravnet_conv import GravNetConv
      7 from .gated_graph_conv import GatedGraphConv
      8 from .res_gated_graph_conv import ResGatedGraphConv

~/anaconda3/envs/py38/lib/python3.8/site-packages/torch_geometric/nn/conv/gravnet_conv.py in <module>
     10 
     11 try:
---> 12     from torch_cluster import knn
     13 except ImportError:
     14     knn = None

~/anaconda3/envs/py38/lib/python3.8/site-packages/torch_cluster/__init__.py in <module>
     18     t_major, t_minor = expected_torch_version
     19     if major != t_major or (major == t_major and minor != t_minor):
---> 20         raise RuntimeError(
     21             f'Expected PyTorch version {t_major}.{t_minor} but found '
     22             f'version {major}.{minor}.')

RuntimeError: Expected PyTorch version 1.4 but found version 1.10.

My pytorch version is indeed 1.10:

print(torch.__version__)
1.10.0+cu102

Any idea what is happening?

It’s saying your PyTorch version is 1.10 but it requires version 1.4. Maybe you need to update PyTorch-Geometric? Note that it’s a separate library.