How to configure Syntastic as python3 check instead of python2

In MacVim, I save the following code as test.py

print "Hello world! python2" 

which, apparently, is wrong with python3, but after running: w to save the file, there is no error message for it. The following is the part ~ / .vimrc that deals with Syntastic:

 " Syntastic "" Recommended settings set statusline+=%#warningmsg# set statusline+=%{SyntasticStatuslineFlag()} set statusline+=%* let g:syntastic_always_populate_loc_list = 1 let g:syntastic_auto_loc_list = 1 let g:syntastic_check_on_open = 1 "" Display checker-name for that error-message let g:syntastic_aggregate_errors = 1 "" I use the brew to install flake8 let g:syntastic_python_checkers=['flake8', 'python3'] 

How to make Syntastic detect this type of error when running test.py in the terminal:

 NingGW:Desktop ninggw$ python3 test.py File "test.py", line 1 print "Hello world! python2" ^ SyntaxError: Missing parentheses in call to 'print' 

Here's what: SyntasticInfo said:

 Syntastic version: 3.8.0-10 (Vim 800, Darwin, GUI) Info for filetype: python Global mode: active Filetype python is active The current file will be checked automatically Available checkers: flake8 python Currently enabled checker: flake8 Press ENTER or type command to continue 
+6
source share
2 answers

flake8 is a Python package. It uses Python's built-in tools to parse the code, so it accepts the syntax for the version of Python that it belongs to .

How to install it for your python3 installation depends on how this installation was installed - if it doesn't suit you using pip .

+3
source

From the FAQ :

4.11. Q. How to check scripts written for different versions of Python?

a. Install Python version manager, for example virtualenv or pyenv , activate the environment for the corresponding version of Python and install the checkers that you want to use in it. Set g:syntastic_python_checkers respectively in vimrc and run Vim from a virtual environment.

If you start Vim from the desktop manager, and not from the terminal, you may need to write shell scripts around your checkers in order to activate the virtual environment before performing the actual checks. Then you need to specify the appropriate g:syntastic_python_<checker>_exec variables g:syntastic_python_<checker>_exec for shell scripts.

+1
source

Source: https://habr.com/ru/post/1012974/


All Articles