如何将Syntastic设置为Python3检查器而不是Python2?

11
在MacVim中,我将以下代码保存为test.py。
print "Hello world! python2"

在Python3中似乎出了问题,但是当我运行:w保存文件后,它没有显示任何错误信息。接下来是~/.vimrc的一部分,所有内容都与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']
如何让Syntastic在我在终端运行test.py时检测到这种类型的错误:
NingGW:Desktop ninggw$ python3 test.py
  File "test.py", line 1
    print "Hello world! python2"
                               ^
SyntaxError: Missing parentheses in call to 'print'

以下是:SyntasticInfo所说的内容:

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

你的 flake8 属于哪个 Python 安装?我认为这是关键。 - ivan_pozdeev
2个回答

6

哦,我明白了,将flake8安装到我的python2中!现在我用pip3重新安装了它... - VimNing
太好了!谢谢!在收到您的答案之前,我尝试使用pylint暂时解决它,现在pylint和flake8都指出了错误,前者说test.py | 1列1个错误|[syntax-error]Missing parentheses in call to 'print'[python/pylint],后者说 test.py|1列21个错误| SyntaxError: invalid syntax[E999][python/flake8] - VimNing

1

来自常见问题解答

4.11. Q. 如何检查针对不同版本的Python编写的脚本?

A. 安装Python版本管理器,例如virtualenvpyenv,激活与所需Python版本相应的环境,并在其中安装要使用的检查器。在您的vimrc中相应地设置g:syntastic_python_checkers,然后从虚拟环境运行Vim。

如果您是从桌面管理器而不是终端启动Vim,则可能需要编写包装器脚本以围绕您的检查器,在运行实际检查之前激活虚拟环境。然后,您需要将相关的g:syntastic_python_<checker>_exec变量指向包装器脚本。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接