Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
FDUguchunhui opened this issue Mar 4, 2025 · 0 comments
Open

Comments

@FDUguchunhui
Copy link

/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant