2

Hello I'm having trouble while trying to use flake8 and flycheck, I know this probably this isn't a issue with flycheck per se but I need some guidance about what is happening.

The problem

On a python file when I run flycheck-buffer I get this error:

Suspicious state from syntax checker python-flake8: Flycheck checker python-flake8 returned non-zero exit code 1, but its output contained no errors: Traceback (most recent call last):
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/checker.py", line 501, in run_ast_checks
    ast = self.processor.build_ast()
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/processor.py", line 211, in build_ast
    return compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc3' in position 1850: surrogates not allowed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/bin/flake8", line 11, in <module>
    sys.exit(main())
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/main/cli.py", line 16, in main
    app.run(argv)
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/main/application.py", line 322, in run
    self._run(argv)
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/main/application.py", line 306, in _run
    self.run_checks()
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/main/application.py", line 244, in run_checks
    self.file_checker_manager.run()
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/checker.py", line 350, in run
    self.run_serial()
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/checker.py", line 334, in run_serial
    checker.run_checks(self.results_queue, self.statistics_queue)
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/checker.py", line 606, in run_checks
    self.run_ast_checks()
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/checker.py", line 504, in run_ast_checks
    row, column = self._extract_syntax_information(exception)
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/checker.py", line 476, in _extract_syntax_information
    if column > 0 and token and isinstance(exception, SyntaxError):
TypeError: unorderable types: str() > int()

Try installing a more recent version of python-flake8, and please open a bug report if the issue persists in the latest release.  Thanks!

Now the pointed position is just a word with an accented character in the document block of a function. But that's not my problem here, because when I run flake8 on the file from my zshell it works just fine.

What I've tried

A lot of related issues suggest updating flake8 but as of today I have the most recent version:

~ ❯ flake8 --version
3.2.1 (mccabe: 0.5.3, pycodestyle: 2.2.0, pyflakes: 1.3.0) CPython 3.6.0 on Darwin

Within emacs using M-: (process-lines "flake8" "--version") this is recognized as well:

("3.2.1 (pyflakes: 1.3.0, mccabe: 0.5.3, pycodestyle: 2.2.0) CPython 3.5.2 on Darwin")

Another similar issues on internet suggest there's something wrong with the environment, and that could be the problem but in this case I'm not so sure since flake8 on emacs works without issues, only flycheck fails.

This is the flycheck-verify-setup output:

Syntax checkers for buffer views.py in python-mode:

  python-flake8
    - may enable:         yes
    - executable:         Found at /Users/lcl/.pyenv/shims/flake8
    - configuration file: Not found

  python-pylint
    - may enable:         yes
    - executable:         Found at /usr/local/bin/pylint
    - configuration file: Not found

  python-pycompile
    - may enable: yes
    - executable: Found at /Users/lcl/.pyenv/shims/python

The following checker is explicitly selected for this buffer:

  python-flake8
    - major mode:         `python-mode' supported
    - may enable:         yes
    - executable:         Found at /Users/lcl/.pyenv/shims/flake8
    - configuration file: Not found

Flycheck Mode is enabled.  Use M-x universal-argument C-c ! x to
enable disabled checkers.

--------------------

Flycheck version: 31snapshot (package: 20161216.1227)
Emacs version:    25.1.1
System:           x86_64-apple-darwin16.3.0
Window system:    mac

You can notice that I use pyenv I have globally installed python 3.6.0 and have a pyenv-virtualenv with python 3.5.2 activated, I use pyenv-mode to activate the pyenv virtualenv. This virtualenv is the one who has flake8 installed.

This is my flycheck-compile while using the checker python-flake8:

-*- mode: compilation; default-directory: "~/Documents/nextgen/devel/ticket.dev/nextgen/users/" -*-
Compilation started at Thu Dec 29 00:03:12

/Users/lcl/.pyenv/shims/flake8 --format\=default --stdin-display-name /Users/lcl/Documents/nextgen/devel/ticket.dev/nextgen/users/views.py - < /Users/lcl/Documents/nextgen/devel/ticket.dev/nextgen/users/views.py
Traceback (most recent call last):
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/checker.py", line 501, in run_ast_checks
    ast = self.processor.build_ast()
  File "/Users/lcl/.pyenv/versions/3.5.2/envs/ticket/lib/python3.5/site-packages/flake8/processor.py", line 211, in build_ast
    return compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcc3' in position 1850: surrogates not allowed

We see the same error as I told you but listen to this, if I run M-x shell and then copy the same command used by flycheck, it all works fine!

Output in M-x shell:

/Users/lcl/.pyenv/shims/flake8 --format=default --stdin-display-name /Users/lcl/Documents/nextgen/devel/ticket.dev/nextgen/users/views.py - < /Users/lcl/Documents/nextgen/devel/ticket.dev/nextgen/users/views.py
<panel.dev/nextgen/users/views.py - < /Users/lcl/Documents/nextgen/devel/ticket.dev/nextgen/users/views.py
/Users/lcl/Documents/nextgen/devel/ticket.dev/nextgen/users/views.py:179:5: C901 'UserActions.post' is too complex (19)
/Users/lcl/Documents/nextgen/devel/ticket.dev/nextgen/users/views.py:327:5: C901 'UserUpdateView.form_valid' is too complex (14)
/Users/lcl/Documents/nextgen/devel/ticket.dev/nextgen/users/views.py:507:5: C901 'UserCreateView.form_valid' is too complex (15)

I did started to use the exec-path-from-shell package but the error is still happening, what could be happening? Why is flycheck the only missing the party?

1 Answer 1

1

I had the same problem, flake8 gives the error because it doesn't get utf-8 as input. Doing C-h C RET my settings were:

Defaults for subprocess I/O:
  decoding: - -- undecided-unix (alias: unix)

  encoding: 1 -- iso-latin-1-unix (alias: iso-8859-1-unix latin-1-unix)

Adding (set-default-coding-systems 'utf-8) to .emacs that changed to:

Defaults for subprocess I/O:
  decoding: U -- utf-8-unix (alias: mule-utf-8-unix)

  encoding: U -- utf-8-unix (alias: mule-utf-8-unix)

Which results in emacs giving the buffer to flake8 as utf-8.

2
  • A lot has changed in my setup, I'm no longer using pyenv and it works well now, but I'm curious, what function does it get called on C-h C RET? I don't have the default mappings. Thanks.
    – zzantares
    May 5, 2017 at 1:43
  • C-h C is describe-coding-system May 6, 2017 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.