vim-hug-neovim-rpc icon indicating copy to clipboard operation
vim-hug-neovim-rpc copied to clipboard

Specify a path to the python program with the module installed

Open hwalinga opened this issue 4 years ago • 12 comments

I have multiple python virtual environments installed on my pc, but I don't want to install pynvim in all of them.

Would it be possible to specify a certain path to an python executable that has this module installed, instead of letting vim search in the PATH for the first python executable it can find?

hwalinga avatar Feb 11 '20 22:02 hwalinga

https://github.com/roxma/nvim-yarp#requirements

g:python3_host_prog pointed to your python3 executable, or echo exepath('python3') is not empty.

You can specify it by g:python3_host_prog.

Shougo avatar Feb 11 '20 23:02 Shougo

That's true for nvim-yarp, but not for this plugin.

hwalinga avatar Feb 11 '20 23:02 hwalinga

Hm. OK. g:neovim_rpc#py is for this plugin.

Shougo avatar Feb 11 '20 23:02 Shougo

No, that also doesn't work.

It really does not seem that this plugin has that feature. This is the code from this plugin:

if has('pythonx')
    let g:neovim_rpc#py = 'pythonx'
    let s:pyeval = function('pyxeval')
elseif has('python3')
    let g:neovim_rpc#py = 'python3'
    let s:pyeval = function('py3eval')
else
    let g:neovim_rpc#py = 'python'
    let s:pyeval = function('pyeval')
endif

hwalinga avatar Feb 11 '20 23:02 hwalinga

You can send PR for the plugin. Why doesn't?

Shougo avatar Feb 12 '20 00:02 Shougo

Looking into this, I could not find a way to change the Python executable that is used for the interface. I could not find any information about it and it might be that this is already determined the moment the vim starts and cannot be changed afterwards. As a personal work-around I append the place where I install the pynvim package to sys.path:

py3 sys.path.append('/home/hielke/.venv/py3/lib/python3.7/site-packages/')

hwalinga avatar Feb 16 '20 15:02 hwalinga

@hwalinga You can specify the path by 'pythonthreedll' option.

						*'pythonthreedll'*
'pythonthreedll'	string	(default depends on the build)
			global
			{only available when compiled with the |+python3/dyn|
			feature}
	Specifies the name of the Python 3 shared library. The default is
	DYNAMIC_PYTHON3_DLL, which was specified at compile time.
	Environment variables are expanded |:set_env|.
	This option cannot be set from a |modeline| or in the |sandbox|, for
	security reasons.

Shougo avatar Feb 16 '20 23:02 Shougo

So this issue should be closed.

Shougo avatar Feb 16 '20 23:02 Shougo

@Shougo It may desirable to be using a project's virtual environment for other purposes, but to find the system-wide (or a different venv's) interpreter for pynvim.

OJFord avatar Jun 01 '20 10:06 OJFord

Assuming pynvim is installed system-wide (which in OP's case it looks like it wasn't) a workaround is to create (or modify) your venvs as:

python -m venv --system-site-packages {VENV_PATH}

OJFord avatar Jun 01 '20 10:06 OJFord

@Shougo It may desirable to be using a project's virtual environment for other purposes, but to find the system-wide (or a different venv's) interpreter for pynvim.

Unfortunately, this is Vim's feature. vim-hug-neovim-rpc cannot fix the problem. You can change the interpreter path by pythonthreedll option. So I have recommended to close it as won't fix.

Shougo avatar Jun 02 '20 02:06 Shougo

One way to solve this is to figure out what python version is the vim runtime using

:py3 print(sys.path)

This output:

['/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/usr/local/opt/[email protected]/Frameworks/Python.framewor
k/Versions/3.9/lib/python3.9', '/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/usr/local/op
t/[email protected]/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages', '_vim_path_']

In my case it was probably the supplied Python with the MacOS. I'm using pyenv + virtualenvs normally in the terminal, but vim picks the OS Py, so probably a PATH issue.

To fix the missing packages I just use pip install using python executable that is included in the vim path.

/usr/local/opt/python/bin/python3 -m pip install pynvim

svilenkov avatar Dec 26 '20 13:12 svilenkov