Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch Python Version for Vim & Syntastic

Is it possible to change the python version used by syntastic for syntax checking?

As the Issue https://github.com/scrooloose/syntastic/issues/385 indicates I could use virtual-env. But is it also possible just with syntastic or vim commands?

like image 621
mjb4 Avatar asked Apr 20 '14 01:04

mjb4


2 Answers

Easiest solution:

Add this to you .vimrc

 let g:syntastic_python_python_exec = 'python3'  let g:syntastic_python_checkers = ['python'] 

This is the straightforward solution to switch to python3.

like image 54
Raphael D. Avatar answered Oct 09 '22 03:10

Raphael D.


The below is no longer necessary, and might screw up if you're forced to work on a strictly python 2.x script.

The best option is to leave the Syntastic defaults alone, and to use conda to manage separate environments for python 3 and 2 (each with their own version-specific installs of flake8, pyflakes, etc), and to switch to the appropriate environment to edit each file. Syntastic will then call python/flake8/whatever else according to the paths set in the activated environment.


From the Syntastic repository README:

Q. The python checker complains about syntactically valid Python 3 constructs...

A. Configure the python checker to call a Python 3 interpreter rather than Python 2, e.g:

let g:syntastic_python_python_exec = '/path/to/python3'

Add that line to your .vimrc - that should fix your problem.

like image 22
naught101 Avatar answered Oct 09 '22 01:10

naught101