How to Resolve Modulenotfounderror: No Module Named 'Google.Colab'

Google Colab : ModuleNotFoundError: No module named 'base_positioner'

This could happen if you haven't mounted your Drive on Colab to the backend properly and also possibly if your file layout in Drive is distinct from the file layout in Colab. Are you running the import command without running the following code?

from google.colab import drive
drive.mount('/content/gdrive')
%cd /content/gdrive/My Drive

If you are doing that then this won't work, as this is a pre-requisite for the mounting to take place (i.e. not running the cells sequentially). You can also try restarting Google Colab and this often fixes any strange errors.

Update:

As you mentioned, the import error likely happens due to its configuration in the main file (i.e. it requires the file to be in the .py format to be imported just as import base_positioner).

To import .ipynb extension file you will need to follow the following process:
If you want to import A.ipynb in B.ipynb write

import import_ipynb
import A

The import_ipynb module can be installed via pip or any other relevant ways.

pip install import_ipynb

Colab error : ModuleNotFoundError: No module named

Your file layout in Drive is distinct from the file layout in Colab.

In order to use Drive files in Colab, you'll need to mount your Drive on the Colab backend using the following snippet:

from google.colab import drive
drive.mount('/content/drive')

Then, if you have a file like mylib.py, you'll want to %cd /content/drive in order to change your working directory. Then, you can import mylib.

Here's a complete example:

https://colab.research.google.com/drive/12qC2abKAIAlUM_jNAokGlooKY-idbSxi

enter image description here

ModuleNotFoundError in Colaboratory

Try to replace your running command with:

!python -m property_prediction.predict

Or better:

from property_prediction.predict import predict # or whatever your main function is called

predict()

NB: This is of course assuming that you have a module named GP in the folder project_folder

If none of this work, you might be interested in reading this or other articles about imports with python (this is most likely not a problem of google collab)



Related Topics



Leave a reply



Submit