2

I am currently working on a project on Machine Learning on Google Colab which uses Tensorflow API. I created a folder and uploaded it on google drive to run on google Colab. I successfully mounted the google drive and can run the script, But when I try importing another module from the script present in the same folder, it throws an error

    from . import inference
    ImportError: cannot import name 'inference'

I tried finding out a solution for this but found results stating how to import a module directly to the colab notebook.

Please tell me what I am missing here.

Edit: The folder structure is

-nmt
  -nmt.py
  -train.py
  -inference.py
  -utils
    -evaluation.py

and so on. And I am running the python file from the nmt folder. I am getting relative import errors.

1 Answer 1

1

Try this. First, upload the .py file and then save it locally. Then you may use it as you like it.

from google.colab import files
src = list(files.upload().values())[0]
open('library_you_want_to_use.py','wb').write(src)
import library_you_want_to_use
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.