It is June 2021. Python 2 has been officially deprecated for over a year. I am personally never in a position where I want to call the python2 executable.
If I am working in a virtualenv, I start the virtualenv from the shell and then open Neovim. I am never in a
position where I activate or change a virtualenv from within Neovim.
-
From the shell (
/bin/bashfor me) (i.e. NOT within Neovim):- If a
virtualenvis not activated, bothpythonandpython3should point to the python executable. - If a
virtualenvis activated, bothpythonandpython3should point to the python executable defined by thevirtualenv. python <python_script>andpython3 <python_script>should both execute<python_script>with the same executable.pythonandpython3should both start a REPL using the same python executable.
- If a
-
From within Neovim:
:!python <python_script>and:!python3 <python_script>should use the same python executable.- From within a
:terminalwithin Neovim:python <python_script>andpython3 <python_script>should both execute<python_script>with the same executable.pythonandpython3should both start a REPL using the same python executable. Below is a diagram of what I want:
- Put the below in
init.vim:
let &shell='/bin/bash --login'
What does this do?
- Makes the
:term[inal]neovim command read~/.bash_profilewhen a terminal buffer is started.
- Put the below in
~/.bash_profile:
if [[ -n $VIRTUAL_ENV && -e "${VIRTUAL_ENV}/bin/activate" ]]; then
source "${VIRTUAL_ENV}/bin/activate"
fi
What does this do?
- (In combination with #1) Activates the
$VIRTUAL_ENVthat was present whennvimwas started.
