SyntaxError:在 Flask 应用程序的调试模式下无效或缺少编码声明,但在运行模式下则不然

kaz*_*man 8 python debugging pycharm flask

我仅在 PyCharm 中处于调试模式时看到以下错误(按“bug”按钮)。它没有到达断点,但在加载flask.exe 文件时失败。

C:\ProgramData\Anaconda3\envs\workflow_webapp\python.exe "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.2\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 55286 --file C:/ProgramData/Anaconda3/envs/workflow_webapp/Scripts/flask.exe run
pydev debugger: process 18788 is connecting

Connected to pydev debugger (build 183.5429.31)
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\envs\workflow_webapp\lib\tokenize.py", line 390, in find_cookie
    line_string = line.decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2: invalid start byte

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.2\helpers\pydev\pydevd.py", line 1741, in <module>
    main()
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.2\helpers\pydev\pydevd.py", line 1735, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.2\helpers\pydev\pydevd.py", line 1135, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 11, in execfile
    stream = tokenize.open(file)  # @UndefinedVariable
  File "C:\ProgramData\Anaconda3\envs\workflow_webapp\lib\tokenize.py", line 454, in open
    encoding, lines = detect_encoding(buffer.readline)
  File "C:\ProgramData\Anaconda3\envs\workflow_webapp\lib\tokenize.py", line 431, in detect_encoding
    encoding = find_cookie(first)
  File "C:\ProgramData\Anaconda3\envs\workflow_webapp\lib\tokenize.py", line 395, in find_cookie
    raise SyntaxError(msg)
SyntaxError: invalid or missing encoding declaration for 'C:/ProgramData/Anaconda3/envs/workflow_webapp/Scripts/flask.exe'
Run Code Online (Sandbox Code Playgroud)

这是调试配置

该应用程序在正常模式下运行良好:

> C:\ProgramData\Anaconda3\envs\workflow_webapp\python.exe
> C:/ProgramData/Anaconda3/envs/workflow_webapp/Scripts/flask.exe run  *
> Serving Flask app "workflow.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)
Run Code Online (Sandbox Code Playgroud)

运行配置在这里。

版本是:

  • Windows 10 上的 Python 版本:Python 3.6.8 |Anaconda, Inc.| (默认,2018 年 12 月 30 日,18:50:55)[MSC v.1915 64 位 (AMD64)] 在 win32 上

  • 烧瓶版本:1.0.2

  • 皮查姆:2018.3.2

任何指导将不胜感激。