Emacs: How do I set flycheck to Python 3?

后端 未结 4 1522
没有蜡笔的小新
没有蜡笔的小新 2021-02-12 19:01

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

However, when using the tool it reports false positives like print(item, end=\' \') is wrong synt

相关标签:
4条回答
  • 2021-02-12 19:37

    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.

    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.

    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.

    0 讨论(0)
  • 2021-02-12 19:37

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

    How to proceed depends on a number of things.

    If you are using virtual environments then a good place to start is on this page from flycheck's creator's dotfiles

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

    If you are not using virtual environments then you can just make sure that the pylint executable was installed for python3

    0 讨论(0)
  • 2021-02-12 19:44

    For my case (no pipenv), I got it working by installing the checkers into python3:

    $ pip3 install flake8 pylint mypy
    

    And adding the following to my ~/.emacs.c/custom.el so Flycheck uses python3 for the 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 to call flycheck-verify-setup is very helpful!

    0 讨论(0)
  • 2021-02-12 19:50

    As @Jules mentioned:

    Flycheck simply calls the pylint executable that should be somewhere in your path.

    So it becomes critical that the correct flake8 version is accessible within emacs. Since you are using pipenv, you should be sure to first install flake8 within your project's environment, and then ensure that your environment is activated before launching emacs.

    From within your project root directory:

    pipenv install flake8
    pipenv shell
    

    You can then launch emacs from the commandline, and flycheck will connect with the correct version of flake8 for your project.

    0 讨论(0)
提交回复
热议问题