如何为 python 3 配置 spacemacs?

How do I configure spacemacs for python 3?

我想使用 spacemacs 进行 python 开发,但我在 Python 3 个构造上看到语法错误,例如 print(*(i + 1 for i in range(n))async def foo():。将 shebang 添加到我的文件(#!/usr/bin/python3#!/usr/bin/env python3)没有帮助。

我需要进行哪些配置更改才能使用特定的 python 版本?理想情况下是每个项目或每个文件,但全局总比没有好。我在系统范围内安装了 2.7 和 3.4,在 ~/local 中安装了 3.5(~/local/bin 在我的 $PATH 中)。

您不必更改 spacemacs 配置。您可以只使用 pyenv 来管理 python 版本。

安装pyenv然后在终端

$ pyenv install 3.5.1
$ pyenv global 3.5.1

默认 python 解释器将设置为 python 3.5.1.

$ python --version
Python 3.5.1

有关详细信息,请参阅 here

此外,将 python-shell-interpreter 设置为 python3 也可能会解决问题。

需要设置的变量是flycheck-python-pycompile-executable,改为"python3"

要获得对 async 的支持,必须使用 emacs25(注意 debian 将同时安装 emacs24emacs25,并使用 emacs24 默认情况下)。