Emacs: How to install flycheck on Python 3?

I installed flycheck for Emacs Python on Ubuntu 15.04.

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

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

How to check box for Python 3?

In the Github documentation, he does not mention whether it supports Python 2 or 3 (Python only).

Also, if possible, give me a hint why the elpa tool doesn't offer suggestions, for example. basic types of Python.

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 
+14
source share
4 answers

Flycheck has several checkers for each supported language (and many others provided by the community ). Almost all of them use external tools for checking buffers, and most of them can be customized.

The easiest way to find out which checkers are supported and how to set them up is through introspection. Open the python file and call flycheck-verify-setup or press Cc ! v Cc ! v . This shows you a new buffer with a list of syntax checks used in python mode. Each control panel is a hyperlink to the documentation, where it is described, and configuration parameters are indicated.

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

+13
source

For my case (without pipenv) I earned by installing checkers in python3 :

 $ pip3 install flake8 pylint mypy 

And add the following to my ~/.emacs.c/custom.el so that Flycheck uses python3 for checkers:

 (custom-set-variables '(flycheck-python-flake8-executable "python3") '(flycheck-python-pycompile-executable "python3") '(flycheck-python-pylint-executable "python3")) 

As @ uwe-koloska noted, using Ctrl-c ! v calling flycheck-verify-setup very useful!

+9
source

Flycheck simply calls the pylint executable, which should be somewhere in your path. If this executable was installed pip for python2, then pylint will check the syntax of python2, if it was installed for pip (sometimes called pip3) for python3, then pylint will check the syntax of python3.

How to act depends on several things.

If you use virtual environments, a good place to start is on this page from the flycheck creator dotfiles

This line is also needed: (add-hook 'flycheck-mode-hook #'flycheck-virtualenv-setup)

If you are not using virtual environments, you can just make sure that the pylint executable has been installed for python3

+7
source

As @Jules mentioned:

Flycheck simply calls the Pylint executable, which should be somewhere in your path.

Therefore, it becomes critical that the correct version of flake8 is available in emacs. Since you are using pipenv , you must first install flake8 in your project environment and then make sure your environment is activated before running emacs.

From the root directory of your project:

 pipenv install flake8 pipenv shell 

You can then start emacs from the command line and flycheck will contact the correct version of flake8 for your project.

+1
source

All Articles