11

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?

4

2 回答 2

14

感谢Lunaryorn 在 github 上的回答,我意识到还有一个 flycheck-set-pylint-executable。现在一切都在以下配置下正常工作:

(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)
于 2015-07-16T14:08:45.187 回答
5

今天解决这个问题,我找到了另一个解决方案(它适用于当前版本的 flycheck,截至 2020 年 6 月)。

只需.dir-locals.el为给定项目创建适当的设置。喜欢:

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

(创建文件M-x add-dir-local-variable也可以,但请记住在命令周围添加双引号)

于 2020-06-08T20:28:48.110 回答