Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 560
ronseg Avatar asked Sep 23 '18 13:09

ronseg


People also ask

How do I fix module not found in Google Colab?

Update your Google Chrome version to >=80 and it works perfectly! Show activity on this post. an internet connection problem: so check your internet connection first, or try opening other sites.

How do I install Python libraries in Google Colab?

Installing a Python package in Google Colab is simple using the pip command along with the exclamation mark (!). The exclamation mark at the start of a cell allows to run a shell command, and pip is the Python package installer that allows to install Python libraries.

How do I load a drive in Colab?

To import google drive, write this code in code section of colab and run it by Ctrl+Enter . On running code, one blue link and a text box will appear we need to provide a permission text. So click the link and a new tab will open where you will be asked for permission to access google drive.


1 Answers

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

like image 73
Bob Smith Avatar answered Oct 08 '22 14:10

Bob Smith