neoclide / coc-python

Python extension for coc.nvim, fork of vscode-python
575 stars 51 forks source link

Auto-install neovim and jedi python packages #161

Open Rizhiy opened 4 years ago

Rizhiy commented 4 years ago

Currently, to make the plugin work properly I have to install neovim and jedi packages into every virtual environment I use. This is rather annoying if you have a lot of them (I have 20+).

I think there are two options:

wookayin commented 4 years ago

+1 I agree that there should be an easy way to auto install necessary packages.

You can actually configure it on your own to have auto-install scripts in your init.vim or vimrc. For example:

function! Autoinstall_pynvim()
  let l:python3_neovim_path = substitute(system("python3 -c 'import pynvim; print(pynvim.__path__)' 2>/dev/null"), '\n\+$', '', '')
  if empty(l:python3_neovim_path)
    execute ("!python3 -m pip install pynvim")
  endif
endfunction

autocmd VimEnter * Autoinstall_pynvim()
" or :call timer_start(0, { -> Autoinstall_pynvim() })

To see more advanced or full setup, you can have a look at my init.vim.

skriems commented 4 years ago

@Rizhiy I currently have

let g:python3_host_prog = "$HOME/.virtualenvs/nvim3/bin/python"
let g:python_host_prog = "$HOME/.virtualenvs/nvim2/bin/python"

with the respectively created envs where I install neovim and jedi and have set "python.venvPath": "~/.virtualenvs", in my coc-settings.

How do you see that your setup does not work? What kind of error message to you get? I'm just wondering if my setup works, because I don't get any errors, but completion does not work very well (I don't work much in Python these days)

Rizhiy commented 4 years ago

@skriems I use conda instead of venv, still:

I have tried using:

let g:python3_host_prog = "$HOME/anaconda3/envs/nvim/bin/python"

And pointed "python.venvPath" to my ~/anaconda3/envs, but this led to jedi not being able to find any of my installed packages.

As I currently understand, python host must match the environment python for language server to work properly.

yujinyuz commented 4 years ago

@Rizhiy I currently have this in my coc-settings.json

  "python.jediEnabled": true,
  "python.jediPath": "~/.pyenv/versions/nvim/lib/python3.7/site-packages",

And I don't have any problems with it

WhyNotHugo commented 4 years ago

Just tell nvim where you system python is, and it'll use that:

let g:python3_host_prog = '/usr/bin/python'

Just make sure you've you OS's python-pynvim package installed, as well as python-jedi.