Reputation: 1487
project
+
+--------+app1
| +
| +-------------+models.py <---+
| |
| |
| | from ..app1.models import Model
+--------+app2 |
| + |
| +--------------+models.py +
|
+
I want to import the Model
class in module models
from app1 into app2. When attempting to use from ..app1.models import Model
, I receive the error Attempted relative import beyond top-level package
.
Upvotes: 0
Views: 38
Reputation: 481
use:
import sys
sys.path.append("..") # or sys.path.append(".")
print (os.getcwd())
from app1.models import ModelClassName
Upvotes: 1