awslabs / dgl-lifesci

Python package for graph neural networks in chemistry and biology
Apache License 2.0
696 stars 144 forks source link

cannot import name 'collate_center' from 'utils' (/usr/local/lib/python3.7/dist-packages/utils/__init__.py) #183

Open meniapi opened 2 years ago

meniapi commented 2 years ago

can someone help me? I get this error on Colab

_ImportError Traceback (most recent call last) in () ----> 1 from utils import collate_center, reaction_center_prediction, output_candidate_bonds_for_a_reaction

ImportError: cannot import name 'collatecenter' from 'utils' (/usr/local/lib/python3.7/dist-packages/utils/init.py)

mufeili commented 2 years ago

This should import from this file rather than a package called utils. What's your current working directory?

meniapi commented 2 years ago

Hello, thank you for replying,

I run it on colab for the moment with the ipynb file, so my directory is the default (/content/) but even if I run it on visual studio it gives me the same error. Could you help please?

mufeili commented 2 years ago

What's your working directory? Have you tried changing working directory to examples/reaction_prediction/rexgen_direct?

meniapi commented 2 years ago

Hello again,

I have changed the directory into this,

/content/gdriveexamples/reaction_prediction/rexgen_direct

With this command

if IN_COLAB:

Mount the Google Drive at mount

mount='/content/gdrive' print("Colab: mounting Google drive on ", mount)

drive.mount(mount)

Switch to the directory on the Google Drive that you want to use

import os drive_root = mount + "examples/reaction_prediction/rexgen_direct"

Create drive_root if it doesn't exist

create_drive_root = True if create_drive_root: print("\nColab: making sure ", drive_root, " exists.") os.makedirs(drive_root, exist_ok=True)

Change to the directory

print("\nColab: Changing directory to ", drive_root) %cd $drive_root

But still I get this error

ImportError Traceback (most recent call last)

in () ----> 1 from utils import collate_center, reaction_center_prediction, output_candidate_bonds_for_a_reaction 2 3 max_k = 80 # Maximum number of candidate bond changes to select 4 5 full_data = [center_dataset[i] for i in range(len(center_dataset))] ImportError: cannot import name 'collate_center' from 'utils' (/usr/local/lib/python3.7/dist-packages/utils/__init__.py) Can you help me please? From: Mufei Li ***@***.***> Date: Wednesday, 29 June 2022 at 10:47 To: awslabs/dgl-lifesci ***@***.***> Cc: Marinapres ***@***.***>, Author ***@***.***> Subject: Re: [awslabs/dgl-lifesci] cannot import name 'collate_center' from 'utils' (/usr/local/lib/python3.7/dist-packages/utils/__init__.py) (Issue #183) What's your working directory? Have you tried changing working directory to examples/reaction_prediction/rexgen_direct? — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: ***@***.***>
meniapi commented 2 years ago

Hello again,

I have changed the directory into this,

/content/gdriveexamples/reaction_prediction/rexgen_direct

With this command

_if IN_COLAB:

Mount the Google Drive at mount

mount='/content/gdrive' print("Colab: mounting Google drive on ", mount)

drive.mount(mount)_

_# Switch to the directory on the Google Drive that you want to use import os drive_root = mount + "examples/reaction_prediction/rexgen_direct"

Create drive_root if it doesn't exist

create_drive_root = True if create_drive_root: print("\nColab: making sure ", drive_root, " exists.") os.makedirs(drive_root, exist_ok=True)

Change to the directory

print("\nColab: Changing directory to ", drive_root) %cd $driveroot

But still I get this error

ImportError Traceback (most recent call last) in () ----> 1 from utils import collate_center, reaction_center_prediction, output_candidate_bonds_for_a_reaction 2 3 max_k = 80 # Maximum number of candidate bond changes to select 4 5 full_data = [center_dataset[i] for i in range(len(center_dataset))]

ImportError: cannot import name 'collate_center' from 'utils' (/usr/local/lib/python3.7/dist-packages/utils/init.py)

Can you help me please?

mufeili commented 2 years ago

I'm not familiar with Colab. What's the result of running the code snippet below?

import os
directory = os.getcwd()
print(directory)

If the directory is correct, then you will want to research about forcing relative import over absolute import in python.

meniapi commented 1 year ago

Hello, thank you for replying,

I run it on colab for the moment with the ipynb file, so my directory is the default (/content/) but even if I run it on visual studio it gives me the same error. Could you help please?

From: Mufei Li @.> Date: Wednesday, 29 June 2022 at 05:54 To: awslabs/dgl-lifesci @.> Cc: Marinapres @.>, Author @.> Subject: Re: [awslabs/dgl-lifesci] cannot import name 'collate_center' from 'utils' (/usr/local/lib/python3.7/dist-packages/utils/init.py) (Issue #183)

This should import from this filehttps://github.com/awslabs/dgl-lifesci/blob/master/examples/reaction_prediction/rexgen_direct/utils.py rather than a package called utils. What's your current working directory?

— Reply to this email directly, view it on GitHubhttps://github.com/awslabs/dgl-lifesci/issues/183#issuecomment-1169505450, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AZLT7IM6452GLYZNT3YY35DVRPCGTANCNFSM52B5M4SQ. You are receiving this because you authored the thread.Message ID: @.***>

mufeili commented 1 year ago

Could you provide detailed instructions for me to try reproducing the issue on visual studio?

Also I'm not sure if this is due to something wrong with your python path like pointing to a package called utils or pointing to a path where there is another utils file.