2

When I launch NeoVim while a virtualenv is activated, I get the following error:

Error detected while processing function provider#python3#Call:
line   18:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "<string>", line 6, in <module>
NameError: name 'execfile' is not defined
Press ENTER or type command to continue

This is what I see when I run :checkhealth provider:


health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: pbcopy

## Python 2 provider (optional)
  - INFO: pyenv: Path: /usr/local/Cellar/pyenv/1.2.16/libexec/pyenv
  - INFO: pyenv: $PYENV_ROOT is not set. Infer from `pyenv root`.
  - INFO: pyenv: Root: /Users/myname/.pyenv
  - INFO: Using: g:python_host_prog = "~/.pyenv/versions/2.7.16/envs/neovim-python2-venv/bin/python"
  - INFO: $VIRTUAL_ENV matches executable
  - INFO: Executable: /Users/myname/.pyenv/versions/2.7.16/envs/neovim-python2-venv/bin/python
  - INFO: Python version: 2.7.16
  - INFO: pynvim version: 0.4.1
  - OK: Latest pynvim is installed.

## Python 3 provider (optional)
  - INFO: pyenv: Path: /usr/local/Cellar/pyenv/1.2.16/libexec/pyenv
  - INFO: pyenv: $PYENV_ROOT is not set. Infer from `pyenv root`.
  - INFO: pyenv: Root: /Users/myname/.pyenv
  - INFO: Using: g:python3_host_prog = "~/.virtualenvs/neovim-python3-venv/bin/python3"
  - WARNING: $VIRTUAL_ENV exists but appears to be inactive. This could lead to unexpected results.
    - ADVICE:
      - If you are using Zsh, see: http://vi.stackexchange.com/a/7654
  - INFO: Executable: /Users/myname/.virtualenvs/neovim-python3-venv/bin/python3
  - INFO: Python version: 3.8.0
  - INFO: pynvim version: 0.4.1
  - OK: Latest pynvim is installed.

I don't use Zsh, I use Bash. An attempt to use the snippet from the linked answer in .bashrc did not change the situation.

I do not get the error when not launching NeoVim while a virtualenv is activated.

Removing all Vim plugins did not get rid of the error.

I have tried this with virtualenvs that use both Python 2 and Python 3. The error is the same.

principal
  • 493
  • 1
  • 6
  • 15
  • does this help? https://github.com/deoplete-plugins/deoplete-jedi/wiki/Setting-up-Python-for-Neovim#using-virtual-environments – Jay Mody May 23 '20 at 15:41
  • Unfortunately no. I was already using dedicated virtual environments for neovim, but followed the instructions in the article just to make sure I hadn't missed anything, to no avail. I also tried switching to Zsh and doing what the linked answer suggested, but that got rid of neither the error message, nor the warning produced when running :checkhealth provider. – principal May 23 '20 at 17:02

3 Answers3

1

I believe you have some python code in your init.vim before the line g:python3_host_prog = "~/.virtualenvs/neovim-python3-venv/bin/python3" and while you are launching nvim this code is trying to get executed before knowing which interpreter to use. (At least I had the same problem fighting that half a day)

So just place the mentioned line before the python code.

1

I had a similar issue which has been resolved.

I am using vanilla vim. and based on this thread, execfile() has been remove since python3. Since your python interpreter is python3, this leads vim/nvim to this occurrence. I've looked into ~/.vimrc and replaced the a line execfile(activate_this, dict(__file__=activate_this)) with following:

with open(activate_this) as f:
    code = compile(f.read(), activate_this, 'exec')
    exec(code, dict(__file__=activate_this))

Vim works consistence again.

0

In my case putting g:python3_host_prog = "~/.virtualenvs/neovim-python3-venv/bin/python3" before as suggested in the other answer doesn't work.

Instead, deleting the package and installing it again solved the issue.

Blaszard
  • 30,954
  • 51
  • 153
  • 233