Skip to content
This repository has been archived by the owner on Dec 24, 2020. It is now read-only.

Interpreter keep switching to global one #20

Closed
ntcong opened this issue Mar 30, 2019 · 10 comments
Closed

Interpreter keep switching to global one #20

ntcong opened this issue Mar 30, 2019 · 10 comments
Labels
bug Something isn't working

Comments

@ntcong
Copy link

ntcong commented Mar 30, 2019

I'm using this minimal vimrc

set runtimepath+=~/.vim
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'do': 'yarn install'}
Plug 'honza/vim-snippets'
call plug#end()
let g:coc_snippet_next = '<TAB>'
let g:coc_snippet_prev = '<S-TAB>'
 let g:coc_global_extensions =['coc-snippets','coc-json']
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"

Starting it inside a virtualenv called "buxbot" and vi -u mini.vim
Running :CocCommand -> Select Interpreter

Select pythonPath, current: /usr/local/opt/python/bin/python3.7:
1. /usr/bin/python
2. /usr/local/bin/python
3. /usr/local/opt/python@2/bin/python2.7
4. /Users/user/.virtualenvs/buxbot/bin/python
5. /usr/local/bin/python3

After choosing 4 and run CocCommand again,

Select pythonPath, current: /usr/local/opt/python/bin/python3.7:

Also I think it should choose the current python (which is the virtualenv) by default.

I'm using NVIM v0.3.4 on MacOS

@chemzqm chemzqm added the bug Something isn't working label Mar 30, 2019
@chemzqm
Copy link
Member

chemzqm commented Apr 1, 2019

VSCode create .vscode folder with settings in your project, coc.nvim need to create .vim folder with settings to resolve this problem.

@ntcong
Copy link
Author

ntcong commented Apr 1, 2019

can we use .env file for some basic settings? Creating a .vim folder seems a bit overkill (no plugin is using it)

@mike-hearn
Copy link

I think I'm personally opposed to using .env, only because that's typically used for application configuration by a lot of frameworks (for example, pipenv automatically imports all vars in .env into the shell when activating the virtual environment). I'd personally prefer to keep my editor/IDE config separate from that to avoid any conflicts/complexity it could introduce.

@modesitt-sesco
Copy link

is there any plan on fixing this - how else can I currently use the python interpreter inside /.venv in whatever project I happen to be working in?

@chemzqm
Copy link
Member

chemzqm commented Apr 9, 2019

is there any plan on fixing this

Sure, will fix this ASAP.

@ntcong
Copy link
Author

ntcong commented Apr 9, 2019

1 way to partially fix this is always prefers the current python environment. If vim was started inside a virtualenv then default the interpreter to virtualenv, if it was not then using the default python.

Remembering the choice is great but it might require some hard decision

@CanyonTurtle
Copy link

I am having the same issue as @ntcong when I try to select a different python interpreter with the quickpick menu. The interpreter doesn't seem to change from its initial value no matter what I choose. I am using:

  1. coc-python v1.1.4
  2. pipenv 2018.11.26
  3. python 3.7.3 (built from source)

Additionally, here is the output of :CocInfo on my nvim instance.

  2 ## versions
  3
  4 vim version: NVIM v0.4.0-566-gd5fd0732e
  5 node version: v10.15.2
  6 coc.nvim version: 0.0.64
  7 term: screen-256color
  8 platform: linux
  9
 10 ## Error messages
 11
 12 ## Output channel: snippets
 13
 14 ## Output channel: PythonStarting Jedi Python language engine.
 15 ##########Linting Output - pylint##########
 16 ##########Linting Output - pylint##########
 17 ************* Module linreg
 18 24,0,error,syntax-error:Format strings are only supported in Python 3.6 and greater (<unknown>, line 24)
 19
 20

I am setting up a virtual environment with pipenv (i.e. pipenv shell) and then starting nvim within that environment, and I am sure that the python path of this virtual environment is the very first thing on my path at the time I run nvim. (My path starts like this: /home/CanyonTurtle/.local/share/virtualenvs/pythontests-jqiNevtW/bin:/… Yet, it still selects /usr/bin/python3, and I cannot successfully select anything else. /usr/bin is also on my path.

@chemzqm thank you for working on this issue. I am glad I found coc-python!

@modesitt-sesco
Copy link

modesitt-sesco commented Apr 10, 2019

I agree @ntcong that seems to be the most straightforward. If personal settings need be saved in a .vim directory and can not be saved elsewhere like to the coc-extensions file in ~/.vim, and that this is a larger endeavor, I think these choices should be temporarily removed from :CocCommand until they work as described.

@chemzqm
Copy link
Member

chemzqm commented Apr 10, 2019

Still buggy, need some rework, the logic of this part form vscode-python is quite complex.

@chemzqm
Copy link
Member

chemzqm commented Apr 10, 2019

Fixed by use a json file (~/.config/coc/memos.json) to store the selected python path.

The limitation is it can't support multiple workspaceFolders.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants