【发布时间】:2021-06-03 09:44:18
【问题描述】:
我有一个 Flask 应用程序,在我的 Windows 机器上本地运行时遇到问题。
每当我尝试在我的 venv 中运行它时,我都会收到错误 ModuleNotFoundError: No Module named 'app'
我的项目层次结构如下:
├── app
│ ├────────── __init__.py
│ ├────────── v0_1
│ └────────── v0_2
├── README
├── run.py
└── tests
app/init.py
from flask import Flask
import app.v0_1.v0_1 as V0_1
import app.v0_2.v0_2 as V0_2
import app.messages.messages as MSG
# Create a Flask Application
app = Flask(__name__)
运行.py
from app import app
if __name__ == "__main__":
app.run(host="0.0.0.0")
.vscode/launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"python": "${config:python.pythonPath}"
}
]
}
.vscode/settings.json
{
"python.linting.flake8Enabled": false,
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.pythonPath": "venv\\Scripts\\python.exe"
}
每个文件夹都有自己的init.py
当我构建一个 Docker 文件并运行我的应用程序时,它运行良好。当我尝试在本地运行它时,我遇到了上面提到的错误。错误指向app/__init__.py中的这两个文件:
import app.v0_1.v0_1 as V0_1
import app.v0_2.v0_2 as V0_2
这些文件夹包含我的 API 的蓝图
这里是GitHub上完整项目的链接here
有人可以帮我吗?
【问题讨论】:
标签: python python-3.x flask modulenotfounderror