2016-12-07 1 views
6

En MacVim, je sauve le code suivant comme test.pyComment configurer Syntastic comme vérificateur python3 au lieu de python2

print "Hello world! python2" 

, qui est apparemment mal à python3, mais après avoir exécuté: w pour enregistrer le fichier , il n'y a pas de message d'erreur pour elle, Suite est une partie de ~/.vimrc, ce qui est tout au sujet 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'] 

Comment faire Syntastic détecter ce type d'erreur que je lance test.py dans le Terminal :

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

Voici ce que: SyntasticInfo dit:

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 
+0

quelle installation Python Votre 'flake8' appartenir? Je pense que c'est la clé. –

Répondre

3

flake8 est un paquet Python. Il utilise les fonctions intégrées de Python pour analyser le code, so it accepts syntax for the Python version that it belongs to. Comment l'installer pour votre installation python3 dépend de la façon dont l'installation elle-même a été installée - unless you're fine with using pip Comment l'installer pour votre installation python3 dépend de la façon dont l'installation elle-même a été installée - .

+0

Oh, je viens de le faire, brasser installer le flake8 à mon python2! Je l'ai réinstallé avec pip3 maintenant ... – Niing

+0

Cela fonctionne! Merci! avant que j'aie eu votre réponse j'ai essayé le pylint pour le résoudre temporairement, maintenant les deux pylint et flake8 signalent l'erreur, le premier a dit 'test.py | 1 col 1 erreur | [syntax-error] Les parenthèses manquantes dans l'appel à 'print' [python/pylint] 'et la dernière' test.py | 1 col 21 erreur | SyntaxError: syntaxe invalide [E999] [python/flake8] ' – Niing

1

De l'FAQ:

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

A. Install a Python version manager such as virtualenv or pyenv , activate the environment for the relevant version of Python, and install in it the checkers you want to use. Set g:syntastic_python_checkers accordingly in your vimrc , and run Vim from the virtual environment.

If you're starting Vim from a desktop manager rather than from a terminal you might need to write wrapper scripts around your checkers, to activate the virtual environment before running the actual checks. Then you'll need to point the relevant g:syntastic_python_<checker>_exec variables to the wrapper scripts.