I am working on multiple projects written in Python 2 or Python 3. flake8
is already installed both for 2 and 3. It's OK to run in command shell.
E.g, running flake8
on Python 2 project
$ python2.7 -m flake8 foo.py
$ python3.6 -m flake8 foo.py
foo.py:14:43: E999 SyntaxError: invalid syntax
My question is how to config flake8 for different projects to choose py2 or py3? I had already created .flake8
configuration files for different projects. My editor is vim
+ w0rp/ale
.
" ===== w0rp/ale ====== "
let g:ale_linters = {
\ 'python': ['flake8', ],
\ }
let g:syntastic_python_flake8_config_file='.flake8'
You don't need to configure anything.
What you want to do is use a virtualenv for each project.
Say we set up a project for Python 3, create a venv (or use a tool for that)
virtualenv -p python3 venv
Activate it,
. ./venv/bin/activate
And install flake8
pip install flake8
Now just open vim, you can check which python and flake8 installation vim is using with
:!which flake8
ALE just uses that.
You should also delete the line
let g:syntastic_python_flake8_config_file='.flake8'
Syntastic is a different plugin and you shouldn't be using it together with ALE.