13

I have just happily configured emacs with autocompletion via jedi and syntax check via flycheck and virtualenvs created within bootstrap. It all seems to work.

I'd like to add the ability to use flycheck-pylint (to get errors in import) but I'm not able to make it work. Even if I change the virtualenv by hand (M-x: pyvenv-activate RET path-to-my-venv) I still see lots of import errors that come from a wrong virtualenv used.

My current initialization code:

(require 'pyvenv)
(add-hook 'after-init-hook #'global-flycheck-mode)
(defun set-flake8-executable ()
  (pyvenv-activate (get-current-buffer-venv))
  (flycheck-set-checker-executable (quote python-flake8)
               (get-current-buffer-flake8)))

where "get-current-buffer-venv" and "get-current-buffer-flake8" are functions that implement my specific setup and are working correctly.

How can I change the interpreter used?

Alessandro Dentella
  • 1,250
  • 2
  • 16
  • 30

2 Answers2

15

Thanks to an answer from Lunaryorn on github i realized there is also a flycheck-set-pylint-executable. Now all is working correctly whith the following configuration:

(defun set-flychecker-executables ()
  "Configure virtualenv for flake8 and lint."
  (when (get-current-buffer-flake8)
    (flycheck-set-checker-executable (quote python-flake8)
                                     (get-current-buffer-flake8)))
  (when (get-current-buffer-pylint)
    (flycheck-set-checker-executable (quote python-pylint)
                                     (get-current-buffer-pylint))))
(add-hook 'flycheck-before-syntax-check-hook
          #'set-flychecker-executables 'local)
John Wiseman
  • 3,081
  • 1
  • 22
  • 31
Alessandro Dentella
  • 1,250
  • 2
  • 16
  • 30
  • 1
    All these years later, this answer isn't so great because the implementation of `get-current-buffer-flake8` and `get-current-buffer-pylint` aren't shown, and they've disappeared from the linked issue on github. – Daniel Martin Dec 01 '22 at 04:45
6

Poking at the problem today, I found another solution (which works with current version of flycheck, as of Jun 2020).

Just create .dir-locals.el with appropriate settings for given project. Like:

((python-mode
  (flycheck-python-flake8-executable . "/home/marcin/.virtualenvs/adgv/bin/python")
  (flycheck-python-pylint-executable . "/home/marcin/.virtualenvs/adgv/bin/python")))

(creating the file with M-x add-dir-local-variable works too, but remember to add double quotes around the command)

Mekk
  • 1,441
  • 10
  • 12