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

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

Open
meniapi opened this issue Jun 28, 2022 · 8 comments

Comments

@meniapi
Copy link

meniapi commented Jun 28, 2022

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 'collate_center' from 'utils' (/usr/local/lib/python3.7/dist-packages/utils/init.py)_

@mufeili
Copy link
Contributor

mufeili commented Jun 29, 2022

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

@meniapi
Copy link
Author

meniapi commented Jun 29, 2022

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
Copy link
Contributor

mufeili commented Jun 29, 2022

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

@meniapi
Copy link
Author

meniapi commented Jun 29, 2022 via email

@meniapi
Copy link
Author

meniapi commented Jun 29, 2022

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?

@mufeili
Copy link
Contributor

mufeili commented Jun 30, 2022

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
Copy link
Author

meniapi commented Oct 11, 2022 via email

@mufeili
Copy link
Contributor

mufeili commented Oct 11, 2022

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

  • Your initial working directory
  • How you invoked the program with visual studio, ideally with screenshots

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.

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

2 participants