Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

importing python module in colab fails

I’m importing a test function in colab but it’s not working as I would expect. I create a simple .py file to test, but I failed to import it despite the fact that I the file can be seen in the path.

from google.colab import drive
import sys
import os
drive.mount('/content/drive', force_remount=True)
path="/content/drive/My Drive/Colab Notebooks/"
sys.path.insert(0,path)
os.chdir(path)
os.listdir(path)

from PPLLM.py import Demo

results in the error message:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-55-eb52ff305968> in <cell line: 1>()
----> 1 from PPLLM.py import Demo

ModuleNotFoundError: No module named 'PPLLM'

The pathing seems to work:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[...,
'PPLLM.py']

The PPLLM file is created in VScode and uploaded to ensure no formatting issues.

The contents are:

def Demo():
  pass

>Solution :

Modules are imported without the extension.

For example, that should fix the issue

from google.colab import drive
import sys
drive.mount('/content/drive', force_remount=True)
path="/content/drive/My Drive/Colab Notebooks/"
sys.path.insert(0,path)

from PPLLM import Demo
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading