PyFlakes-Flymake for Python Programming in Emacs

Flymake is a generic syntax checker for Emacs. Its combination with PyFlakes which is a syntax checker for python makes it a perfect setting for Python programming in Emacs. Here are the steps to make it to work:

1) Install PyFlakes:

  • If you have python setuptools installed, just try
    sudo easy_install pyflakes
  • If you could not use the setuptools, you can also try using your distributions repositories. For Ubuntu/Debian you can try
    sudo apt-get install pyflakes

2) Install Flymake:

  • If you are using Emacs 23+, it is already included in your installation, follow to the next step.
  • You can download it from here, and put it to your emacs directory under your home (usually, “~/.emacs.d” directory).

3) Copy the following to your “init.el” file, which is again located under your Emacs folder (e.g. “~/.emacs.d/init.el”):


;;===== PyFlakes
;; code checking via pyflakes+flymake
(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 "pyflakes" (list local-file))))

 (add-to-list 'flymake-allowed-file-name-masks
 '("\\.py\\'" flymake-pyflakes-init)))

(add-hook 'find-file-hook 'flymake-find-file-hook)

If everything works as planned, when you open a Python file, you should see the “Flymake” minor mode displayed, and it should report if you have syntax errors, or any warnings regarding your code.

Note that I found this setting in this page as a rather more complete setup. However, I found out that for my taste the PyFlakes and the PyComplete is enough to get a good programming environment.

Leave a Reply