Emacs:如何将flycheck设置为Python 3? [英] Emacs: How do I set flycheck to Python 3?

查看:139
本文介绍了Emacs:如何将flycheck设置为Python 3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Ubuntu 15.04上为Emacs Python安装了flycheck。

I've installed flycheck for Emacs Python on Ubuntu 15.04.

但是,使用该工具时,它会报告诸如 print(item ,end ='')由于 end 而语法错误。

However, when using the tool it reports false positives like print(item, end=' ') is wrong syntax due to end.

我知道这是Python 3语法,并且语法错误是由flycheck引起的,是针对Python 2设置的。

I know this is Python 3 syntax, and that the syntax error is caused by flycheck is set up for Python 2.

如何为Python 3设置flycheck呢?

在Github上的文档中,没有提到它是否支持Python 2或3(仅Python)。

In the documentation on Github, it doesn't mention whether it supports Python 2 or 3 (just Python).

如果可能的话,还给我一个提示,为什么elpa工具没有给出建议,例如基本的Python类型。

Also, if possible, give me a hint why the elpa tool is not giving suggestions for e.g. basic Python types.

我的init.el文件在这里:

My init.el file is here:

;; 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


推荐答案

Flycheck有很多检查器对于每个支持的语言(还有更多的由社区提供)。几乎所有它们都使用外部工具来检查缓冲区,并且大多数都可以配置。

Flycheck has a number of checkers for each supported language (and many more provided by the community). Nearly all of them use external tools to check buffers and most of them can be configured.

找出支持哪些检查程序以及如何配置它们的最简单方法是通过内省。打开一个python文件并调用 flycheck-verify-setup 或按 C-c! v 。这将显示一个新缓冲区,其中包含在python-mode中使用的语法检查器的列表。每个检查器都是指向描述它的文档的超链接,并提供了配置选项。

The easiest way to find out what checkers are supported and how to configure them is by introspection. Open a python file and call flycheck-verify-setup or press C-c ! v. This shows you a new buffer with a list of syntax checkers used in python-mode. Every checker is a hyperlink to the documentation where it is described and the configuration options are given.

由于我没有 python-flake8 python-pylint 我只是将变量 flycheck-python-pycompile-executable 设置为 python3 ,一切都变得愉快而快乐。

Since I don't have python-flake8 nor python-pylint I just set the variable flycheck-python-pycompile-executable to "python3" and all is bright and cheerful.

这篇关于Emacs:如何将flycheck设置为Python 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆