Suppose I have:
Project_root (folder)
– source (folder)
– main.py
– functions(folder)
– test.py
– init.py (empty)
Here is the code in main.py:
import os
import sys
from source.functions import test
test.hello()
Code in test.py:
your text
def hello():
your text
print(“Hello World!”)
I’m running this on vs code with anaconda virtual environment. I’m using tensorflow-directml-plugin.
The Error I get is:
line 4, in <module>
from source.functions import test
ModuleNotFoundError: No module named ‘source’
I have tried to import when both the python files are in the same folder and it worked. I also succeeded when the main.py was directly in the root folder but not in a folder that was UNDER the root folder. In this case the main.py is in a folder that is in the root folder and it fails.
Peter Yu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
0