ronseg
ronseg

Reputation: 467

Colab error : ModuleNotFoundError: No module named

While .py files placed in the same folder at Google Colab I get:

ModuleNotFoundError: No module named filename

Although the 'filename' file is in the same folder and imported by:

from filename import *

enter image description here enter image description here

Thanks in advance

Upvotes: 12

Views: 57401

Answers (1)

Bob Smith
Bob Smith

Reputation: 38579

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

Upvotes: 15

Related Questions