roxma / vim-hug-neovim-rpc

EXPERIMENTAL
MIT License
218 stars 28 forks source link

Specify a path to the python program with the module installed #64

Open hwalinga opened 4 years ago

hwalinga commented 4 years ago

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?

Shougo commented 4 years ago

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.

hwalinga commented 4 years ago

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

Shougo commented 4 years ago

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

hwalinga commented 4 years ago

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
Shougo commented 4 years ago

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

hwalinga commented 4 years ago

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/')
Shougo commented 4 years ago

@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 commented 4 years ago

So this issue should be closed.

OJFord commented 4 years ago

@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 commented 4 years ago

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}
Shougo commented 4 years ago

@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.

svilenkov commented 3 years ago

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/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/python39.zip', '/usr/local/opt/python@3.9/Frameworks/Python.framewor
k/Versions/3.9/lib/python3.9', '/usr/local/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload', '/usr/local/op
t/python@3.9/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