Reputation:
The directory structure is as follows:
folder1
__init__.py
file1.py
folder2
file2.py
If I write file2.py as follows:
from folder1 import file1
I get the error No module named 'folder1'
.
If I write file2.py as follows:
from ..folder1 import file1
I get the error ValueError: attempted relative import beyond top-level package
.
How can I import file1 from file2?
Upvotes: 0
Views: 86
Reputation: 308
Try the following:
import sys
sys.path.append("..")
from .. import file1
Upvotes: 1