I've scoured related posts and have tried several things, but I'm still receiving a syntax error in Vim when using Python3 syntax.
The code that is receiving the error:
types_of_people = 10; f"There are {types_of_people} types of people."
The output of running $ vim --version
:
$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 17 2017 10:39:50)
MacOS X (unix) version
Included patches: 1-1100
Compiled by Homebrew
Huge version without GUI. Features included (+) or not (-):
+acl +file_in_path +mouse_sgr +tag_old_static
+arabic +find_in_path -mouse_sysmouse -tag_any_white
+autocmd +float +mouse_urxvt -tcl
-balloon_eval +folding +mouse_xterm +termguicolors
-browse -footer +multi_byte +terminal
++builtin_terms +fork() +multi_lang +terminfo
+byte_offset -gettext -mzscheme +termresponse
+channel -hangul_input +netbeans_intg +textobjects
+cindent +iconv +num64 +timers
-clientserver +insert_expand +packages +title
+clipboard +job +path_extra -toolbar
+cmdline_compl +jumplist +perl +user_commands
+cmdline_hist +keymap +persistent_undo +vertsplit
+cmdline_info +lambda +postscript +virtualedit
+comments +langmap +printer +visual
+conceal +libcall +profile +visualextra
+cryptv +linebreak -python +viminfo
+cscope +lispindent +python3 +vreplace
+cursorbind +listcmds +quickfix +wildignore
+cursorshape +localmap +reltime +wildmenu
+dialog_con -lua +rightleft +windows
+diff +menu +ruby +writebackup
+digraphs +mksession +scrollbind -X11
-dnd +modify_fname +signs -xfontset
-ebcdic +mouse +smartindent -xim
+emacs_tags -mouseshape +startuptime -xpm
+eval +mouse_dec +statusline -xsmp
+ex_extra -mouse_gpm -sun_workshop -xterm_clipboard
+extra_search -mouse_jsbterm +syntax -xterm_save
+farsi +mouse_netterm +tag_binary
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -g -O2 -
U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang -L. -fstack-protector -L/usr/local/lib -
L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -
L/usr/local/opt/readline/lib -L/usr/local/lib -o vim -lncurses -liconv
-framework Cocoa -mmacosx-version-min=10.11 -fstack-protector-strong -
L/usr/local/lib -L/usr/local/Cellar/perl/5.26.0/lib/perl5/5.26.0/darwin-
thread-multi-2level/CORE -lperl -lm -lutil -lc -
L/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/config-3.6m-
darwin -lpython3.6m -framework CoreFoundation -lruby.2.4.2 -lobjc
You may notice above that Vim is including python3
but not python
I have reinstalled Vim using:
$ brew uninstall vim
$ brew install vim --with-python3
I have also tried aliasing python
to my Python3 version:
$ alias python='python3.6'
My PATH:
$ echo $PATH
/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/garythegoat/.rbenv/shims:/usr/bin/python:/usr/local/heroku/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/usr/local/go/bin:/Users/garythegoat/golang/bin
:echo has('python')
returns 1
:echo has('python3')
returns 0
Any suggestions appreciated
This is a difficult question, because this is related to the default python
configured by your OS.
The most useful related question I found is this one.
Both solutions worked for me :
Setting up a Virtual Environment using virtualenv. This is exhausting as you will have to launch the virtual env each time you need to open vim.
Adding let g:syntastic_python_python_exec = 'python3'
to .vimrc
configuration file. I'm not sure if your configuration is based on the syntastic
plugin, but this is something worst looking into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With