我已经在Ubuntu 15.04上为Emacs Python安装了flycheck。
但是,在使用该工具时,由于end
的原因,它会报告诸如print(item, end=' ')
是语法错误的误报。
我知道这是Python 3的语法,语法错误是由为Python 2设置的flycheck引起的。
如何为Python3设置flycheck up?
在Github的文档中,没有提到它是否支持Python 2或3(只支持Python)。
另外,如果可能的话,给我一个提示,为什么elpa工具没有给出建议,例如基本的Python类型。
我的init.el文件在这里:
;; init.el --- Emacs configuration
;; INSTALL PACKAGES
;; -------------------------------------
(require 'package)
;; Primary Emacs repository is MELPA
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
(defvar myPackages
'(better-defaults
elpy ;; Emacs Lisp Python Environment
flycheck ;; flycheck Python syntax-checking
material-theme))
(mapc #'(lambda (package)
(unless (package-installed-p package)
(package-install package)))
myPackages)
;; BASIC CUSTOMIZATION
;; -------------------------------------
(setq inhibit-startup-message t) ;; hide startup message
(load-theme 'material t) ;; load material theme
(global-linum-mode t) ;; enable line numbers globally
(global-flycheck-mode) ;; enable flycheck globally
;; PYTHON CONFIGURATION
;; -------------------------------------
(elpy-enable) ;; enable elpy
;; use flycheck, not flymake with elpy
(when (require 'flycheck nil t)
(setq elpy-modules (delq 'elpy-module-flymake elpy-modules))
(add-hook 'elpy-mode-hook 'flycheck-mode))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(python-shell-interpreter "python3"))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
;; init.el ends here
发布于 2016-08-19 01:54:03
对于每个supported language (以及更多的provided by the community),Flycheck都有许多检查器。几乎所有的工具都使用外部工具来检查缓冲区,并且大多数都可以配置。
要找出支持哪些检查器以及如何配置它们,最简单的方法是通过内省。打开python文件并调用flycheck-verify-setup
或按C-c ! v
。这将显示一个新的buffer,其中包含python-mode中使用的语法检查器的列表。每个检查器都是文档的超链接,其中描述了检查器并给出了配置选项。
因为我既没有python-flake8
也没有python-pylint
,所以我只将变量flycheck-python-pycompile-executable
设置为"python3"
,一切都很愉快。
发布于 2016-06-09 23:56:22
Flycheck只是调用pylint可执行文件,该文件应该在您的路径中的某个位置。如果可执行文件是通过用于python2 pip安装的,则pylint将检查python2语法。如果它是为用于python3的pip (有时称为pip3)安装的,则pylint将检查python3语法。
如何继续取决于许多事情。
如果您使用的是虚拟环境,那么从flycheck创建者的点文件中的on this page开始是一个很好的选择
这一行也是必需的:(add-hook 'flycheck-mode-hook #'flycheck-virtualenv-setup)
如果您没有使用虚拟环境,那么只需确保为python3安装了pylint可执行文件
https://stackoverflow.com/questions/37720869
复制相似问题