How can I make flycheck use virtualenv

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)

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)