gpt4 book ai didi

python - Flask 应用程序中导入错误

转载 作者:太空宇宙 更新时间:2023-11-03 17:52:24 25 4
gpt4 key购买 nike

我有一个申请。下面是树命令的 o/p -

app
|-- main
| |-- lib
| | |-- constants.py
| | |-- helper.py
| | `-- __init__.py
| `-- src
| |-- __init__.py
| `-- web.py

web.py

from flask import Flask, request  
app = Flask(__name__)

from lib.helper import endpoints
.....
Some code
.....
if __name__ == '__main__':
app.run('0.0.0.0', 5433, debug=True)

我收到此错误

ImportError: No module named lib.helper.

我哪里做错了?

最佳答案

from flask import Flask, request  
app = Flask(__name__)

import sys
from os.path import abspath, dirname
sys.path.insert(0, dirname(dirname(abspath(__file__))))

from lib.helper import endpoints
.....
Some code
.....
if __name__ == '__main__':
app.run('0.0.0.0', 5433, debug=True)

关于python - Flask 应用程序中导入错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28942420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com