Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

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

Open
hwalinga opened this issue Feb 11, 2020 · 12 comments
Open

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

hwalinga opened this issue Feb 11, 2020 · 12 comments

Comments

@hwalinga
Copy link

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
Copy link
Collaborator

Shougo commented Feb 11, 2020

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
Copy link
Author

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

@Shougo
Copy link
Collaborator

Shougo commented Feb 11, 2020

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

@hwalinga
Copy link
Author

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
Copy link
Collaborator

Shougo commented Feb 12, 2020

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

@hwalinga
Copy link
Author

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
Copy link
Collaborator

Shougo commented Feb 16, 2020

@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
Copy link
Collaborator

Shougo commented Feb 16, 2020

So this issue should be closed.

@OJFord
Copy link

OJFord commented Jun 1, 2020

@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
Copy link

OJFord commented Jun 1, 2020

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
Copy link
Collaborator

Shougo commented Jun 2, 2020

@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
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants