Reputation: 510
I have a program, program1.py, that has this structure:
Program
--program1.py
--__init__.py
--data\
----__init__.py
----helper_data.py
--classes\
----__init__.py
----helper_class.py
In helper_class.py, there is an import statement from data.helper_data import *
. When I run program1, this works perfectly.
I have a second program, program2.py. I have put program1.py on my PYTHONPATH. In program2.py, I use import program1
. It finds the program, but when running the imports from program1.py, I get the following error stemming from the classes.helper_class: ModuleNotFoundError: No module named 'data.helper_data'
.
I think I vaguely understand what's going on, but I can't figure out the fix or the search terms to find the answer. I've tried changing the import in program1 to from ..data.helper_data import *
and get an error saying I've tried a relative import beyond the parent-level package. I've also tried from .data.helper_data import *
and get the same ModuleNotFoundError.
What can I do?
Upvotes: 0
Views: 210
Reputation: 3457
I think You have to import "sys" package.
import sys
sys.path.append('E:\ToDataScientist') # this is where the "Program" folder exists
from Program.data.helper_data import aa # "aa" is the class or function in helper_data
from Program.data.helper_data import * # include all from helper_data
Upvotes: 1