[英]Python relative import beyond top-level package
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.我想将模块models
中的Model
class 从 app1 导入 app2。 When attempting to use from..app1.models import Model
, I receive the error Attempted relative import beyond top-level package
.尝试使用from..app1.models import Model
时,我收到错误Attempted relative import beyond top-level package
。
use:利用:
import sys
sys.path.append("..") # or sys.path.append(".")
print (os.getcwd())
from app1.models import ModelClassName
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.