2016-12-07 17 views
6

Trong MacVim, tôi lưu sau mã như test.pyLàm thế nào để thiết lập Syntastic như kiểm tra python3 thay vì python2

print "Hello world! python2" 

, mà rõ ràng là sai với python3, nhưng sau khi tôi chạy: w để lưu các tập tin , không có thông báo lỗi cho nó, Sau đây là một phần của ~/vimrc, đó là tất cả về 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'] 

làm thế nào để làm cho Syntastic phát hiện loại hình này lỗi như tôi chạy test.py trong Terminal :

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

Tiếp theo là gì: SyntasticInfo nói:

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

nào cài đặt Python không của bạn 'flake8' thuộc về? Tôi nghĩ đây là chìa khóa. –

Trả lời

3

flake8 là một gói Python. Nó sử dụng các tiện ích tích hợp của Python để phân tích mã, so it accepts syntax for the Python version that it belongs to.

Cách cài đặt để cài đặt python3 của bạn phụ thuộc vào cách cài đặt đã được cài đặt - unless you're fine with using pip.

+0

Ồ, tôi đã nhận được nó, brew cài đặt flake8 vào python2 của tôi! Tôi đã cài đặt lại nó với pip3 ngay bây giờ ... – Niing

+0

Nó hoạt động! cảm ơn! trước khi tôi nhận được câu trả lời của bạn, tôi đã thử pylint để giải quyết nó tạm thời, bây giờ cả pylint và flake8 chỉ ra lỗi này, lỗi trước đây đã nói 'test.py | 1 col 1 | [cú pháp-lỗi] Thiếu dấu ngoặc đơn trong cuộc gọi đến 'in' [python/pylint] 'và lỗi' test.py | 1 col 21 sau | Cú pháp Cú pháp: cú pháp không hợp lệ [E999] [python/flake8] ' – Niing

1

Từ 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.

Các vấn đề liên quan