2016-12-07 14 views
6

W MacVim, zapisać następujący kod jako test.pyJak skonfigurować Syntastic jak python3 sprawdzający zamiast python2

print "Hello world! python2" 

, który jest najwyraźniej źle z python3, ale po biegnę: W celu zapisania pliku nie ma za to komunikat o błędzie, Poniżej znajduje się część ~/.vimrc, która jest o 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'] 

jak Syntastic wykryć ten rodzaj błędu jak biegnę test.py w Terminalu :

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

Oto co: SyntasticInfo powiedział:

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

Która instalacja Pythona Czy Twój 'flake8' należą? Myślę, że to jest klucz. –

Odpowiedz

3

flake8 to pakiet Python. Wykorzystuje wbudowane funkcje Pythona do analizy kodu, so it accepts syntax for the Python version that it belongs to.

Sposób instalacji dla instalacji python3 zależy od sposobu instalacji tej instalacji - unless you're fine with using pip.

+0

Och, właśnie dostałem to, napar zainstalować flake8 do mojego python2! Zainstalowałem go ponownie z pip3 teraz ... – Niing

+0

To działa! dzięki! zanim dostałem twoją odpowiedź, próbowałem pylinta, aby chwilowo go rozwiązać, teraz zarówno pylint, jak i flake8 wskazują błąd, pierwszy z nich powiedział: "test.py | 1 col 1 error | [błąd składni] Brakujące nawiasy w wywołaniu "print" [python/pylint] 'i drugi błąd' test.py | 1 col 21 | SyntaxError: nieprawidłowa składnia [E999] [python/flake8] ' – Niing

1

Z 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.

Powiązane problemy