cjrh / vim-conda

Change conda environments in the Vim editor (with Jedi-vim support)
MIT License
112 stars 25 forks source link

Enable root conda environment #15

Open kiryph opened 8 years ago

kiryph commented 8 years ago

I am using MacVim on OSX 10.10.5 and I have installed miniconda to $HOME/miniconda-py2. I also have adjusted $PATH so that

❯ which -a python
/Users/kiryph/miniconda-py2/bin/python
/usr/bin/python

I would like to enable the default root environment of miniconda in vim for jedi autocompletion.

❯ conda env list
# conda environments:
#
root                  *  /Users/kiryph/miniconda-py2

❯ conda list
# packages in environment at /Users/kiryph/miniconda-py2:
#
...
jedi                      0.8.1                     <pip>
numpy                     1.9.3                    py27_0
...

My vim configuration is following:

❯ tree -L 2 ~/.vim
.vim
├── autoload
│   └── plug.vim
├── plugged
│   ├── jedi-vim
│   └── vim-conda
└── vimrc

4 directories, 2 files

❯ cat ~/.vim/vimrc
filetype plugin indent on
syntax enable
call plug#begin('~/.vim/plugged')
Plug 'davidhalter/jedi-vim'
Plug 'cjrh/vim-conda'
call plug#end()

:python import sys; print '\n'.join(sys.path)
['/Users/kiryph/.vim/plugged/jedi-vim',
 '/Library/Python/2.7/site-packages/jedi-0.8.1_final0-py2.7.egg',
 '/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg',
 '/Library/Python/2.7/site-packages/setuptools-23.0.0-py2.7.egg', 
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python27.zip',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', 
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', 
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', 
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', 
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old',
 '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload',
 '/Users/kiryph/Library/Python/2.7/lib/python/site-packages', 
 '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC',
 '/Library/Python/2.7/site-packages', 
 '/opt/gtk/lib/python2.7/site-packages',
 '/opt/gtk/lib/python2.7/site-packages/gtk-2.0',
 '_vim_path_']  

Jedi-Completion

import numpy.

does not list anything and returns: -- Omni completion (^O^N^P) Pattern not found

UPDATE

Adding to vimrc: python sys.path.append("/Users/kiryph/miniconda-py2/lib/python2.7/site-packages/") resolves it. import numpy. opens now a completion menu.

However, I think the purpose of your plugin is to automate this and in particular setting the sys.path identical to the desired python interpreter.

/usr/bin/python -c "import sys;print sys.path" and /Users/kiryph/miniconda-py2/bin/python -c "import sys;print sys.path" do not have many entries in common.

I was trying the following, but I prefer much more changing it with your plugin.

let s:custom_sys_paths = system('~/miniconda-py2/bin/python -c "import sys;print sys.path"') 
python import vim;import sys; import ast; sys.path.extend(ast.literal_eval(vim.eval("s:custom_sys_paths")))

I think choosing root should not mean to deactivate but set it to the root environment of conda and deactivate means using the defaults identical to those as if vim-conda would not be installed.

cjrh commented 8 years ago

I'll have to look into this in more detail, but it does sound like you've figured out the issue. If you can put a PR together that fixes this, I will merge it.

cjrh commented 8 years ago

Long ago I put a TODO in here:

https://github.com/cjrh/vim-conda/blob/master/plugin/vim-conda.vim#L161

Perhaps that is what you need after all? (or something similar. The details are complicated, I'll need to think about it more.)

kiryph commented 8 years ago

Thanks for your feedback. Right now I do not have the time to create a PR. For now I will stick to the hardcoded solution in my vimrc:

let s:custom_sys_paths = system('~/miniconda-py2/bin/python -c "import sys;print sys.path"') 
python import vim;import sys; import ast; sys.path.extend(ast.literal_eval(vim.eval("s:custom_sys_paths")))
cjrh commented 8 years ago

No problem. Thanks again for the report 👍