【发布时间】:2019-05-24 08:03:08
【问题描述】:
我的代码结构如下:
src/
--- api/
--- --- __init__.py
--- example_app.py
init.py 包含以下代码:
from flask_restplus import Api
from api.about_api import api as about_api
from api.types_api import api as types_api
stackl_api = Api(<Snip>)
stackl_api.add_namespace(about_api)
stackl_api.add_namespace(types_api)
在 example_app.py 中,我尝试这样做:
import stackl_api
app = Flask(__name__)
blueprint = Blueprint('stackl_api', __name__)
stackl_api.init_app(blueprint)
app.register_blueprint(blueprint)
但这给出了错误
from .api import api │
ImportError: attempted relative import with no known parent package
如果执行“从 api 导入 api”,它会给出“ModuleNotFoundError: No module named 'api'”
我可能忘记了什么。你能帮忙吗?
【问题讨论】:
标签: python-3.x import module