16

I would like to use spacemacs for python development, but I see a syntax error on Python 3 constructs, like print(*(i + 1 for i in range(n)) or async def foo():. Adding a shebang to my file (#!/usr/bin/python3 or #!/usr/bin/env python3) does not help.

What configuration changes do I need to make to use a specific python version? Ideally per-project or per-file, but global is better than nothing. I have 2.7 and 3.4 installed system-wide, and 3.5 in ~/local (~/local/bin is in my $PATH).

kai
  • 1,970
  • 2
  • 22
  • 30

2 Answers2

5

You don't have to change spacemacs configurations. You can just use pyenv to manage python version.

Install pyenv then in terminal

$ pyenv install 3.5.1
$ pyenv global 3.5.1

Default python interpreter will be set to python 3.5.1.

$ python --version
Python 3.5.1

For more details see here.

Plus, set python-shell-interpreter to python3 may also fix the problem.

Robin Xing
  • 136
  • 1
  • 5
5

The variable that needed to be set was flycheck-python-pycompile-executable, to "python3".

To get support for async, emacs25 must be used (note debian will install emacs24 and emacs25 side-by-side, and use emacs24 by default).

kai
  • 1,970
  • 2
  • 22
  • 30
  • How do you set that variable and where should you set it? – oliver Oct 11 '18 at 03:15
  • 2
    The easiest way is `SPC-SPC`, `customize-variable`, `flycheck-pycompile-executable`. I'm sure it can be set in your dotfile, check [the docs](https://github.com/syl20bnr/spacemacs/blob/master/doc/DOCUMENTATION.org) for that. – kai Oct 11 '18 at 22:23