Skip to content

NameError: name 'warnings' is not defined. Did you mean: 'Warning' #160

@FDUguchunhui

Description

@FDUguchunhui
/rsrch6/home/biostatistics/cgu3/LSC_GNN/python311/lib/python3.11/site-packages/deeprobust/graph/defense/__init__.py:15: UserWarning: Please install pytorch geometric if you would like to use the datasets from pytorch geometric. See details in https://pytorch-geometric.readthedocs.io/en/latest/notes/installation.html
  warnings.warn("Please install pytorch geometric if you " +
Traceback (most recent call last):
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/python311/lib/python3.11/site-packages/deeprobust/graph/defense_pyg/__init__.py", line 2, in <module>
    from .gcn import GCN
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/python311/lib/python3.11/site-packages/deeprobust/graph/defense_pyg/gcn.py", line 9, in <module>
    from torch_sparse import coalesce, SparseTensor, matmul
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/python311/lib/python3.11/site-packages/torch_sparse/__init__.py", line 39, in <module>
    from .storage import SparseStorage  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/python311/lib/python3.11/site-packages/torch_sparse/storage.py", line 5, in <module>
    from torch_scatter import scatter_add, segment_csr
ModuleNotFoundError: No module named 'torch_scatter'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/lsc_gnn/main.py", line 17, in <module>
    from src.data.utils import GraphData
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/lsc_gnn/src/data/utils.py", line 4, in <module>
    from src.data.data_transform import get_data
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/lsc_gnn/src/data/data_transform.py", line 19, in <module>
    from deeprobust.graph.global_attack import MetaApprox, Metattack
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/python311/lib/python3.11/site-packages/deeprobust/graph/global_attack/__init__.py", line 10, in <module>
    from .prbcd import PRBCD
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/python311/lib/python3.11/site-packages/deeprobust/graph/global_attack/prbcd.py", line 7, in <module>
    from deeprobust.graph.defense_pyg import GCN
  File "/rsrch6/home/biostatistics/cgu3/LSC_GNN/python311/lib/python3.11/site-packages/deeprobust/graph/defense_pyg/__init__.py", line 10, in <module>
    warnings.warn("Please install pytorch geometric if you " +
    ^^^^^^^^
NameError: name 'warnings' is not defined. Did you mean: 'Warning'?

The error is caused by no import warnings in global_attack/init.py and graph/defense/init.py

from .base_attack import BaseAttack
from .dice import DICE
from .mettack import MetaApprox, Metattack
from .random_attack import Random
from .topology_attack import MinMax, PGDAttack
from .node_embedding_attack import NodeEmbeddingAttack, OtherNodeEmbeddingAttack
from .nipa import NIPA

try:
    from .prbcd import PRBCD
except ImportError as e:
    print(e)
    warnings.warn("Please install pytorch geometric if you " +
                  "would like to use the datasets from pytorch " +
                  "geometric. See details in https://pytorch-geom" +
                  "etric.readthedocs.io/en/latest/notes/installation.html")

__all__ = ['BaseAttack', 'DICE', 'MetaApprox', 'Metattack', 'Random', 'MinMax', 'PGDAttack', 'NIPA', 'NodeEmbeddingAttack', 'OtherNodeEmbeddingAttack', 'PRBCD']

When not all torch_sparse, torch_scatter modules are needed, this should only output a warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions