'ModuleNotFoundError: No module named 'funct'
I'm using Google Colab and I want to import a file from the same directory.
I've mounted my Drive:
from google.colab import drive
drive.mount('/content/drive')
And then done:
import sys
sys.path.insert(0, '/content/drive/MyDrive/NLP/Exam')
However when I do
import funct as fu
It throws the following error:
ModuleNotFoundError: No module named 'funct'
Despite the fact that funct.py is in this directory. What could I be missing?
Solution 1:[1]
Can't tell from your description, but if you are in a subpackage at the time of your import (e.g., a subdirectory of your main python program), and you wish to import a module from the same directory, you must give a fully qualified package name. For example, if you have:
- main.py
- mycode/
|-- __init__.py
|-- mymodule.py
|-- funct.py
and you wish to import funct from inside mymodule.py, then you must use:
import mycode.funct as funct
If that's not it, another possible cause is that sys.path has been modified and that the entry containing an empty string ("") has been removed. That is the entry that tells python to search the main script's directory for packages.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sam |
