8

I'm seeing the following error while in debug mode only in PyCharm (pressing the 'bug' button). It does not hit the breakpoint but fails while loading the flask.exe file.

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'

Here is the debug configuration.

The app runs fine in normal mode:

> 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)

The run configuration is here.

The versions are:

  • Python version on Windows 10: Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 18:50:55) [MSC v.1915 64 bit (AMD64)] on win32

  • Flask version: 1.0.2

  • Pycharm: 2018.3.2

Any guidance would be much appreciated.

kaziman
  • 81
  • 1
  • 1
  • 3
  • cheers, I'm not opening any file in the application though. the encoding issue is on the flask.exe file... – kaziman Feb 12 '19 at 13:15
  • 1
    While [davidism's answer to 'Run Flask CLI command with PyCharm debugger'](https://stackoverflow.com/a/51674120/2243745) seems to contain the solution (at least for me), the connected question sounds unrelated. I couldn't find it. – fineliner Oct 22 '19 at 08:37
  • 9
    For me using `Module name = flask` instead of `Script path` in the configuration solved the issue. – fineliner Oct 22 '19 at 08:40
  • Just a note if someone has a simliar error: it occured to me on django 1.11, when I had a cross app model reference and forgot to import the other model. – ger.s.brett Jan 08 '20 at 15:22
  • @fineliner worked for me, thank you! A total black magic voodoo though. – Oleg O Mar 22 '21 at 11:25
  • 7
    In my case it was mistake in interpreter configuration (Python instead of python). Thanks https://blog.ukena.de/posts/2021/encoding-error-when-debugging-a-pipenv-project-using-pycharm-on-osx/ – lukasz.herok Sep 25 '22 at 09:55

0 Answers0