For the python command vim uses the python exetuable it finds first in the $PATH variable. However, for me this can change depending what project I work on (using virtual environments). Is there a way to fix this to one particular executable?

NB. On the internet I find a lot of sources vim uses the python executable it is compiled with. It seems this has changed.

Output of :version of vim:

VIM - Vi IMproved 8.1 (2018 May 18, compiled Nov 09 2019 12:59:40)
Included patches: 1-2269
Modified by team+vim@tracker.debian.org
Compiled by team+vim@tracker.debian.org
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl               +cmdline_compl     +emacs_tags        +insert_expand     +modify_fname      +netbeans_intg     +ruby              +termguicolors     +visualextra
+arabic            +cmdline_hist      +eval              +job               +mouse             +num64             +scrollbind        +terminal          +viminfo
+autocmd           +cmdline_info      +ex_extra          +jumplist          +mouseshape        +packages          +signs             +terminfo          +vreplace
+autochdir         +comments          +extra_search      +keymap            +mouse_dec         +path_extra        +smartindent       +termresponse      +wildignore
-autoservername    +conceal           -farsi             +lambda            +mouse_gpm         +perl              +sound             +textobjects       +wildmenu
+balloon_eval      +cryptv            +file_in_path      +langmap           -mouse_jsbterm     +persistent_undo   +spell             +textprop          +windows
+balloon_eval_term +cscope            +find_in_path      +libcall           +mouse_netterm     +postscript        +startuptime       +timers            +writebackup
+browse            +cursorbind        +float             +linebreak         +mouse_sgr         +printer           +statusline        +title             +X11
++builtin_terms    +cursorshape       +folding           +lispindent        -mouse_sysmouse    +profile           -sun_workshop      +toolbar           -xfontset
+byte_offset       +dialog_con_gui    -footer            +listcmds          +mouse_urxvt       -python            +syntax            +user_commands     +xim
+channel           +diff              +fork()            +localmap          +mouse_xterm       +python3           +tag_binary        +vartabs           +xpm
+cindent           +digraphs          +gettext           +lua               +multi_byte        +quickfix          -tag_old_static    +vertsplit         +xsmp_interact
+clientserver      +dnd               -hangul_input      +menu              +multi_lang        +reltime           -tag_any_white     +virtualedit       +xterm_clipboard
+clipboard         -ebcdic            +iconv             +mksession         -mzscheme          +rightleft         +tcl               +visual            -xterm_save
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0
-I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/libdrm -I/usr/include/pango-1.0 -I/usr/includ
e/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/us
r/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time  -
g -O2 -fdebug-prefix-map=/build/vim-yrDlon/vim-8.1.2269=. -fstack-protector-strong -Wformat -Werror=format-security -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-
1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinu
x  -lcanberra -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.30/CORE -lperl -ldl -lm -lpthrea
d -lcrypt  -L/usr/lib/python3.7/config-3.7m-x86_64-linux-gnu -lpython3.7m -lcrypt -lpthread -ldl -lutil -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lm -lruby-2.
5 -lpthread -lgmp -ldl -lcrypt -lm
  • Can you clarify: you want vim not to use the first python in it's path (such as a virtual environment python), but to only use one particular one? I ask only because this seems to be the opposite of general requests, and I just want to make sure :) – D. Ben Knoble Feb 15 '20 at 17:08
  • Yes, exactly. I have plugins depending on the Python interface and I don't want to install the required dependencies in all my virtual environments. I now have a py3 sys.path.append('/path/to/those/dependencies/') which works fine, but I wonder if I can just change what python executable py3 uses. – Hielke Walinga Feb 15 '20 at 19:50
  • Can you edit your Q to add the output from :version? – D. Ben Knoble Feb 15 '20 at 19:53
  • @D.BenKnoble Done. – Hielke Walinga Feb 15 '20 at 20:00

Your Answer

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

Browse other questions tagged or ask your own question.