Flask拒绝在vscode调试中加载服务器

时间:2019-04-15 18:20:43

标签: python flask visual-studio-code

我无法让烧瓶在vscode中使用迷你项目和默认设置运行,而无法在仅安装烧瓶的conda环境中运行。无论我尝试什么,烧瓶运行都将启动。转到http://127.0.0.1:5000/将给出以下错误消息。是否从提示符运行都没有关系。以调试方式运行或以任何其他flask -m运行方式运行。

代码:

from flask import Flask
app = Flask(__name__)

@app.route("/")
def home():
    return "Hello, Flask!"


flask run
     * Serving Flask app "app.py"
     * Environment: production
       WARNING: Do not use the development server in a production environment.
       Use a production WSGI server instead.
     * Debug mode: off
     * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

{
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        },

错误消息

File "F:\Anaconda3\envs\sgpython\lib\site-packages\flask\cli.py", line 330, in __call__
rv = self._load_unlocked()
File "F:\Anaconda3\envs\sgpython\lib\site-packages\flask\cli.py", line 317, in _load_unlocked
self._app = rv = self.loader()
File "F:\Anaconda3\envs\sgpython\lib\site-packages\flask\cli.py", line 372, in load_app
app = locate_app(self, import_name, name)
File "F:\Anaconda3\envs\sgpython\lib\site-packages\flask\cli.py", line 246, in locate_app
'Could not import "{name}".'.format(name=module_name)
flask.cli.NoAppException: Could not import "server".

1 个答案:

答案 0 :(得分:0)

您似乎缺少一些软件包。尝试运行pip3 install -r requirements.txt --ignore-installed,看看是否可行。

此外-确保将启动配置FLASK_APP条目设置为应用程序正在运行的目录。

Python解释器的位置必须包含在PATH环境变量中。