I'm using Python 3.7.1 on macOS Mojave Version 10.14.1
This is my directory structure:
man/
Mans/
man1.py
MansTest/
SoftLib/
Soft/
SoftWork/
manModules.py
Unittests/
man1test.py
man1.py
contains the following import statement, which I do not want to change:
from Soft.SoftWork.manModules import *
man1test.py
contains the following import statements:
from ...MansTest.SoftLib import Soft
from ...Mans import man1
I need the second import in man1test.py
because man1test.py
needs access to a function in man1.py
.
My rationale behind the first import (Soft) was to facilitate the aforementioned import statement in man1.py
.
Contrary to my expectation, however, the import statement in man1.py
gives rise to:
ModuleNotFoundError: No module named 'Soft'
when I run
python3 -m man.MansTest.Unittests.man1test
from a directory above man/.
Is there any way to resolve this error without changing the import statement in man1.py
and without adding anything to sys.path?
Edit: python3 -m man.ManTest.Unittests.man1test
from the original version of the question changed to python3 -m man.MansTest.Unittests.man1test
This question is related to
python
python-3.x
python-import
For me when I created a file and saved it as python file, I was getting this error during importing. I had to create a filename with the type ".py" , like filename.py and then save it as a python file. post trying to import the file worked for me.
Source: Stackoverflow.com