What is the correct flymake configuration for emacs? (using Python.el)
Asked Answered
R

2

7

I am using emacs as python IDE. I am having flymake installed, however, it shows the following error whenever I work with a .py file

Error (flymake): Flymake: Failed to launch syntax check process 'pycheckers' with args (string-operations_flymake.py): Searching for program: no such file or directory, pycheckers. Flymake will be switched OFF

My .emacs configuration for flymake is as follows:

;; flymake
(add-to-list 'load-path "~/.emacs.d/vendor")
(add-hook 'find-file-hook 'flymake-find-file-hook)
(when (load "flymake" t)
  (defun flymake-pyflakes-init ()
    (let* ((temp-file (flymake-init-create-temp-buffer-copy
               'flymake-create-temp-inplace))
       (local-file (file-relative-name
            temp-file
            (file-name-directory buffer-file-name))))
      (list "pycheckers"  (list local-file))))
   (add-to-list 'flymake-allowed-file-name-masks
             '("\\.py\\'" flymake-pyflakes-init)))
(load "~/.emacs.d/vendor/flymake-cursor.el")
(global-set-key [f10] 'flymake-goto-prev-error)
(global-set-key [f11] 'flymake-goto-next-error)

Any suggestions on how to resolve this

Religiosity answered 15/12, 2012 at 18:18 Comment(0)
G
4

Install flycheck. Should work out of the box.

Grenoble answered 15/12, 2012 at 19:14 Comment(1)
Then the correct answer might as well be "install VSCode. Should work out of the box". Shame that wasn't the question!Royall
E
0

I will explain how to use flymake in GNU Emacs 29.4.

Let's assume that we want to use flymake on this Python file (see code block below) that uses syntax compliant to Python 3.10. Note that the last print statement has a syntax erorr: it is missing the closing parentheses.

print('foo')
print('bar')
print('baz'

We need to install a syntax checker for Python 3.10. I will install flake8, all available syntax checkers supported for Python by flymake is in python-flymake-command.

python3.10 -m pip install flake8

Upon execution of the command, you can get the location where it was installed using pip show, in the field Location.

pip show flake8
Name: flake8
Version: 7.1.1
Summary: the modular source code checker: pep8 pyflakes and co
Home-page: https://github.com/pycqa/flake8
Author: Tarek Ziade
Author-email: [email protected]
License: MIT
Location: /home/rodrigo/.local/lib/python3.10/site-packages
Requires: mccabe, pycodestyle, pyflakes
Required-by: 

In my system, the binary flake8 was located in /home/rodrigo/.local/bin/flake8.

We need to tell Emacs where the binary flake8 is located, we have two options: (1) we could add /home/rodrigo/.local/bin/ to $PATH in the shell where Emacs will be started or (2) we could add /home/rodrigo/.local/bin/ to the Emacs variable exec-path. I'll use (1).

We can start Emacs by running the command shown below. Note: I have used emacs -Q, so that none of my configurations are loaded just to show how vanilla Emacs behaves. Note: we don't need to load a configuration file because in GNU Emacs 29.4, flymake is a built-in package.

PATH="/home/rodrigo/.local/bin:$PATH" emacs -Q /tmp/a.py

If we execute flymake-mode, the last line should be underlined. If we move the point to the underlined line, the syntax error is shown in the minibuffer (see screenshot below).

Emacs showing Python buffer with underlined line

If we execute flymake-show-buffer-diagnostics, the buffer *Flyamke diagnostics for `a.py`* will be shown (see screenshot below).

Emacs showing buffer "a.py" and "Flymake diagnostics for `a.py'

Elevate answered 6/9 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.