6

New emacs/python user here.
I'm trying to set up flycheck to work (and use flake8).

This is the relevant part in my init.el:

(require 'python-mode)
(add-to-list 'auto-mode-alist '("\\.py$" . python-mode))
(add-hook 'python-mode-hook 'flycheck-mode)

When I open a python file my modeline includes Py FlyC-
From the Flycheck manual I learned that this means Flycheck could not automatically find a suitable checker.

When I run M-x flycheck-select-checker and select python-flake8 it returns:

Configured syntax checker python-flake8 cannot be used

I'm using OSX 10.9 with homebrew and these versions:

$ emacs --version
GNU Emacs 24.3.50.1
$ flake8 --version
2.1.0 (pep8: 1.4.6, pyflakes: 0.7.3, mccabe: 0.2.1) CPython 2.7.5 on Darwin
$ which flake8
/usr/local/bin/flake8
$ python --version
Python 2.7.5
$ which python
/usr/local/bin/python

As for the emacs packages, they are installed from melpa and marmalade

python-mode version: 6.0.10
Flycheck version: 0.15snapshot (package: 20131105.1502)

Any hints on how to get this working?

jeroentbt
  • 472
  • 6
  • 8
  • Do you have python-flake8 installed and on your path? – Squidly Nov 06 '13 at 11:52
  • Not to the problem, but is there any specific reason, why you do not use the built-in Python mode? –  Nov 06 '13 at 13:59
  • @lunaryorn Because the internet tells me it's better. I'm not in the place to judge so I'm just following the herd here... – jeroentbt Nov 06 '13 at 16:11
  • 1
    @jeroentbt It used to be, but the built-in Python mode was greatly improved in Emacs 24.3, so much of what you can read about this miss isn't true anymore. –  Nov 06 '13 at 19:02
  • @lunaryorn thanks for the heads-up. I'm going back to the default then... (http://stackoverflow.com/a/15672445/1929897) – jeroentbt Nov 07 '13 at 08:52

1 Answers1

13

Do M-: (executable-find "flake8"). If it says nil, add /usr/local/bin to your exec-path.

On OS X GUI applications do not inherit variables from the shell configuration and thus have a different $PATH. Hence, being able to run flake8 in the terminal doesn't imply, that Emacs is able to find it as well.

You may also want to look at the exec-path-from-shell package.

  • Excellent! Thank you! /usr/local/bin was indeed not in my `exec-path`, once set via customise everything worked. I will probably be using `exec-path-from-shell`. – jeroentbt Nov 06 '13 at 16:09
  • I think I ran into exact same problem, but how do I "add `/usr/local/bin` to `exec-path`"? – LWZ Aug 21 '14 at 21:17
  • @LWZ By adding a corresponding `add-to-list` call to your `init.el`. –  Aug 22 '14 at 08:38