Switch Python Version for Vim & Syntastic

后端 未结 8 1087
忘了有多久
忘了有多久 2020-12-24 05:15

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

相关标签:
8条回答
  • 2020-12-24 05:51

    Just to iterate on Zaar Hai's script a bit, something like this should work and be a bit more robust.

    #!/usr/bin/env bash
    
    _python=$(command -v python)
    
    [[ "$(uname -s)" =~ Darwin ]] && IS_OSX=true
    
    if [[ "$IS_OSX" ]]; then
        if command -v 'greadlink' >/dev/null 2>&1; then
            greadlink -f "$_python"
        else
            echo 'Install coreutils!' >&2
        fi
    else
        readlink -f "$_python"
    fi
    
    0 讨论(0)
  • 2020-12-24 05:59

    In spite of all the answers here, I still find the recommendation from the FAQ to be the best. I have added this to my .vimrc so that I can easily switch between python versions.

    function Py2()
      let g:syntastic_python_python_exec = '/usr/local/bin/python2.7'
    endfunction
    
    function Py3()
      let g:syntastic_python_python_exec = '/usr/local/bin/python3.6'
    endfunction
    
    call Py3()   " default to Py3 because I try to use it when possible
    

    With those functions installed, it's easy to switch python version right within vim with :call Py2() or :call Py3() depending on what I need at the moment. No need to exit vim and activate a different virtualenv as the popular answer would have you do.

    0 讨论(0)
提交回复
热议问题