We discussed about python vim interop sometime back. We figured
how vim picks up the python interop lib from the system location instead of
virtualenv. And thus language services like jedi
may be installed on the
system instead of each virtualenv.
With vim version 8.0.1451
, it is possible to now select the PYTHONHOME
to
use with an option. See the patch and pull request.
There’s a small change in behavior. Default option is to pick up python packages available, which points to the virtualenv. It implies now the language service packages are looked up in virtualenv. However we can use a new setting to take us back to older behavior.
set pythonthreehome=/usr
This ensures the python library is picked up from /usr
dir. In our case,
jedi
continues to be a system install and is picked appropriately. Let’s do a
quick comparison of the behavior with and without pythonthreehome
set.
Without pythonthreehome not set (default)
" Run these commands within vim ex mode
:py3 import sys; print(sys.prefix); print(sys.base_prefix)
/tmp/trial/.venv
/tmp/trial/.venv
:py3 import sys; print(sys.path)
['/tmp/trial/.venv/lib/python36.zip', '/tmp/trial/.venv/lib/python3.6', '/tmp/trial/.venv/lib/python3.6/lib-dynload', '/usr/lib64/python3.6', '/usr/lib/python3.6', '/tmp/trial/.venv/lib/python3.6/site-packages', '_vim_path_']
With pythonthreehome set
" Run these commands within vim ex mode
:py3 import sys; print(sys.prefix); print(sys.base_prefix)
/usr
/usr
:py3 import sys; print(sys.path)
['/usr/lib/python36.zip', '/usr/lib/python3.6', '/usr/lib/python3.6/lib-dynload', '/usr/lib/python3.6/site-packages', '_vim_path_']
Namaste!