I am trying to use Python in vim, but it doesn't work despite vim having the +python3 option.

:python print("hello")


E319: Sorry, the command is not available in this version

Question: How can this problem be fixed?

The :version command's output:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 06 2019 17:31:41)
Included patches: 1-1453
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
Huge version without GUI.  Features included (+) or not (-):
+acl               -dnd               +listcmds          +postscript        +timers
+arabic            -ebcdic            +localmap          +printer           +title
+autocmd           +emacs_tags        -lua               +profile           -toolbar
-autoservername    +eval              +menu              -python            +user_commands
-balloon_eval      +ex_extra          +mksession         +python3           +vertsplit
+balloon_eval_term +extra_search      +modify_fname      +quickfix          +virtualedit
-browse            +farsi             +mouse             +reltime           +visual
++builtin_terms    +file_in_path      -mouseshape        +rightleft         +visualextra
+byte_offset       +find_in_path      +mouse_dec         -ruby              +viminfo
+channel           +float             +mouse_gpm         +scrollbind        +vreplace
+cindent           +folding           -mouse_jsbterm     +signs             +wildignore
-clientserver      -footer            +mouse_netterm     +smartindent       +wildmenu
-clipboard         +fork()            +mouse_sgr         +startuptime       +windows
+cmdline_compl     +gettext           -mouse_sysmouse    +statusline        +writebackup
+cmdline_hist      -hangul_input      +mouse_urxvt       -sun_workshop      -X11
+cmdline_info      +iconv             +mouse_xterm       +syntax            -xfontset
+comments          +insert_expand     +multi_byte        +tag_binary        -xim
+conceal           +job               +multi_lang        +tag_old_static    -xpm
+cryptv            +jumplist          -mzscheme          -tag_any_white     -xsmp
+cscope            +keymap            +netbeans_intg     -tcl               -xterm_clipboard
+cursorbind        +lambda            +num64             +termguicolors     -xterm_save
+cursorshape       +langmap           +packages          +terminal
+dialog_con        +libcall           +path_extra        +terminfo
+diff              +linebreak         -perl              +termresponse
+digraphs          +lispindent        +persistent_undo   +textobjects

The problem was solved.

The :python3 or :pythonx (:py3 or :pyx) should be used instead of the simple :python.

See :h python3 and :h pythonx.

So, :py3 print("hello") gives hello as expected.

Also, to see what version of Python is being used, do:

:pyx import sys
:pyx print(sys.version)

in my case it gives

3.6.9 (default, Nov  7 2019, 10:44:02)
[GCC 8.3.0]

Check :help if-pyth: you need to use :python3.

  • :h if-python gives E149: Sorry, no help for if-python. Also, :helpgrep if-python gives E480: No match: if-python. – MiniMax Feb 19 '20 at 6:29
  • @MiniMax see edits – D. Ben Knoble Feb 19 '20 at 13:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.