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:
[...,
'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