Reputation: 1233
I know there are a lot of questions asking the same I'm now asking, but I've tried most of their answers and they doesn't fix my problem.
I have a file named fileA.py
where I need to call and import fileB.py
. Until now i was doing this:
# in fileA.py
import fileB.py
And it was working. But suddenly now it does not. It gives me this error:
ModuleNotFoundError: No module named 'fileB'
They are on the same folder at the same level. I've tried all of these solutiones:
import folder.fileB
from . import fileB
import fileB.py
And still same error. How can I fix this?
Upvotes: 5
Views: 16543
Reputation: 858
Make sure that your present working directory
in terminal while executing your code is same as that of fileA.py
.
Upvotes: 2
Reputation: 1150
It's better to use absolute imports. Starting from the root, assume you have a folder called folder
which holds your modules, you would import it like so:
from folder import fileB
If folder
is not the root of the code, then start from the root source folder:
from root_source_folder.some_package.folder import fileB
Upvotes: 4