0

I am using Ubuntu 22 and the default (OS) Python version is 3.10.6.

I don't need this python version; rather I need 3.8.16. I've installed it and set the g:python3_host_prog to its path to use it when I use NeoVim.

But I've noticed that when I run :!python3 -V it outputs the default Python version which is 3.10.6. I guess it still looks for the python executable in PATH and finds the first instance of it. I don't really understand the purpose of python3_host_prog if it doesn't temporarily change the provider for the running instance of NeoVim.

Is there a way to force NeoVim to use the wanted version? Why are they different?

Currently my temporary solution is to wrap the NeoVim command by adding a prefix of the wanted executable while it runs and then remove it using bash.

1
  • Did you found an answer to your question? Is the answer proposed addressed your problem? If so I'll be glad if you could accept it. It allow the question to rest :-) Apr 3, 2023 at 14:41

1 Answer 1

0

There are at least 3 access to Python from Vim/Neovim that can be configured differently:

  1. The shell access (when running :!python3 -v)
  2. The python linked to Vim/Neovim (when running :py3 print(sys.version)
  3. The python used by coc.nvim
  4. The python used by deoplete

The shell access

The python version is here the one used by the shell and it is selected the same way it is selected for the shell using the PATH environment variable.

Remark: I believe the first python3 executable in your path is still Python 3.10.6 which makes it the default shell Python and the default Vim shell Python.

To change that you should to adapt the your PATH environment variable to make Python 3.8.16 the first Python found by the shell.

The python linked to Vim/Neovim

It is the Python version used by a number of plugin using Python (e.g.: ultisnips)

In particular if you are using deoplete

For Vim

This one is defined when Vim is linked (it depend on the compilation/linkage of Vim/Neovim). You can't change it without recompiling Vim/Neovim or changing the Vim/Neovim executable you are using.

For Neovim

It is determined by the value of g:python3_host_prog

Python used by coc

The coc plugins used Python interpreter to determine how to complete Python code. You can configure the interpreter used by changing the python.pythonPath parameter of the ~/.vim/coc-settings.json that you can edit with the :CocConfig command.

coc-settings.json

{
    "python.pythonPath": "/usr/bin/python3"
}

Python used by deoplete-jedi

It is determined by the value of g:python3_host_prog

It is important it correspond to the version of Python you are using if you want deoplete to complete correctly the method of the python package you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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