snap-stanford / ogb

Benchmark datasets, data loaders, and evaluators for graph machine learning
https://ogb.stanford.edu
MIT License
1.93k stars 397 forks source link

better import exception #114

Closed yuhui-zh15 closed 3 years ago

yuhui-zh15 commented 3 years ago

This small edit aims to fix ogb import error but without any user notification:

Before:

Python 3.7.7 (default, May  6 2020, 04:59:01) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ogb.graphproppred import PygGraphPropPredDataset
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'PygGraphPropPredDataset' from 'ogb.graphproppred' (/Users/yuhui/Desktop/ogb/ogb/graphproppred/__init__.py)

After:

Python 3.7.7 (default, May  6 2020, 04:59:01) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ogb.graphproppred import PygGraphPropPredDataset
dlopen(/Users/yuhui/opt/miniconda3/lib/python3.7/site-packages/torch_sparse/_version.so, 6): Library not loaded: @rpath/libtorch_cpu.dylib
  Referenced from: /Users/yuhui/opt/miniconda3/lib/python3.7/site-packages/torch_sparse/_version.so
  Reason: image not found
No module named 'dgl'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'PygGraphPropPredDataset' from 'ogb.graphproppred' (/Users/yuhui/Desktop/ogb/ogb/graphproppred/__init__.py)

This might not be the best solution, but at least show something to users for debugging purposes. :)

weihua916 commented 3 years ago

Thank you for your idea! We deliberately did not print anything, because we do not want to print

No module named 'dgl'

for Pytorch Geometric users. Basically, we do not want to force our users to install both torch_geometric and dgl even if they just use one of them.

Whenever users want to use PygGraphPropPredDataset, we assume the torch_geometric and its associated packages have been installed without any issue.

weihua916 commented 3 years ago

One idea is not to print anything if the error is the failure of importing dgl or torch_geometric.

yuhui-zh15 commented 3 years ago

I see your concerns now. So basically I just ran pip install ogb and got an unknown ImportError. I didn't know why this error occurs and I should install any additional packages. After these modifications, I understood this error is due to missing packages, and I successfully imported it after installing torch_geometric. I think it might be more reasonable to print something in this case?...

Closing this pull request now as the current solution is not appropriate. :)