Giter Club home page Giter Club logo

vim-conda's Introduction

Important Notice

This project is no longer supported.

You can keep in sending PR:s, but we encourage you to use vim-conda-activate instead.

Thanks to all the collaborators who took part into this journey. :)

vim-conda

This is a Vim plugin to support Python development using the Conda environment manager.

NOTE for Neovim users: If Neovim finds python on your $PATH, it assumes this is Python 2 (and likewise for python3 being treated as Python 3). If you start Neovim from a shell with an activated Conda env that uses Python 3, you're going to have problems because the conda env exposes a binary called python, but which is really 3 and not 2. Because of this, you will have to use the Neovim option of setting g:python_host_prog to point to a valid Python 2, into which you must also have pip installed the required neovim client.

Install

Vundle is the recommended way. Add this to the section in your vimrc file where all your plugin statements appear:

Plugin 'cjrh/vim-conda'

Edit: Vundle is no longer the recommended way!

I much prefer vim-plug which works in a similar way to Vundle, but seem just generally better all round. To add vim-conda, you need this:

Plug 'cjrh/vim-conda'

Super-short summary

When developing Python with Vim, there are two Pythons of interest:

  1. The one that executes your code in a shell command, i.e. :!python %
  2. The (embedded in Vim) one that jedi-vim uses to provide code completion.

Conda is concerned with the first one, i.e. the "shell Python". The second one depends on how you have Vim set up with respect to its own Python scripting support.

This plugin provides a command, CondaChangeEnv, that will

  1. Change the $PATH and $CONDA_DEFAULT_ENV environment variables inside the Vim process, so that new launched processes will have the same environment as if they were launched from a Conda env.
  2. Change the embedded Python sys.path inside Vim so that tools like jedi-vim will provide code completion for the selected env.

Demo

gif screencast of plugin demo

Introduction

The Vim editor can be used to develop Python code. One popular workflow is to edit the text of a code module (e.g. a .py file), and then execute the code with a shell command, such as

:!python %

(where % will be expanded to the name of the current file). Which python will run? Why, the one in the system path of course! But what happens if there is more than one Python executable in the system path? The first one to be found will be the one that runs.

This forms the basis of how virtual environments work. The Conda tool is an environment manager for Python; it also supports package management as part of its feature set, but we are not concerned with that here. Conda allows the user to create multiple, separate Python installations, and switch between them on the command line. It does this by modifying the $PATH (or PATH on Windows) environment variable.

vim-conda makes it easy to perform switching environments right from inside Vim. Now you never have to leave, so the >300 upvoted question on StackOverflow on "how to quit" need no longer concern you ;)

This plugin provides only one single command, CondaChangeEnv, which you can map to an unused key. You can call the command like so:

:CondaChangeEnv<ENTER>

You can map it to a key (e.g. in your vimrc file) like so:

map <F4> :CondaChangeEnv<CR>

When the command is executed, a wildmenu will appear showing the currently available Conda environments on your system. By selection one, the changes to $PATH and the embedded-python sys.path are made. (Unfortunately, the key for triggering wildmode and moving through the wildmenu is hard-coded to <Tab>; I still haven't learned enough vimscript to figure out how to use a user setting.)

In the list of environments, you will also see root as an option if you had previously changed to a non-root env. Selecting root is the same as doing a deactivate in the sense that all the changes made previously are rolled back.

Likewise, when you change from one environment to another, the change is clean in the sense that changes from the first env are reset, before changes for the new env are made. Exactly as would happen on the command line.

Details

The CondaChangeEnv command will trigger wildmode allowing you to tab through the existing Conda environments on your system. When an environment is selected, the following happens:

  • A new environment variable called $CONDA_DEFAULT_ENV is created inside the running Vim process
  • The $PATH variable is set to be the selected Conda env, plus the associated /Scripts folder, as per the usual way the activate script supplied by Conda would modify the path. Note that the $PATH environment variable inside the running Vim process is modified.
  • The sys.path list of the embedded Python instance inside the running Vim process is modified to include the entries for the selected Conda env. This is done so that the Jedi-Vim package will automatically be able to perform code completion within the selected env.

Notes

While testing, I found that I needed the following settings in my vimrc in order to suppress some errors related to other packages:

let g:jedi#force_py_version = 2
let g:UltisnipsUsePythonVersion = 2

More testing is needed to make sure that all the configurations work.

In order to suppress the message of vim-conda environment information on vim startup - add the variable in the 'vimrc' file.

let g:conda_startup_msg_suppress = 1

In order to keep the message of vim-conda environment information on vim startup - you can either comment out the above variable or add the below variable in the 'vimrc' file.

let g:conda_startup_msg_suppress = 0

In order to avoid a warning when opening vim without an environment activated, add the variable in the 'vimrc' file.

let g:conda_startup_wrn_suppress = 1

vim-conda's People

Contributors

cjrh avatar idroz avatar jfishe avatar lexsong avatar machbio avatar matthias-wright avatar rddunphy avatar ryanfreckleton avatar ubaldot avatar xywei avatar zyjux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-conda's Issues

Neovim support?

Hi,

when installing the plugin in neovim, i am getting the following error message

Error detected while processing function <SNR>25_SetCondaPlainPath..provider#python#Call:
line   18:
NameError("name 'vim' is not defined",)
Traceback (most recent call last):
  File "/Users/cmav/miniconda2/lib/python2.7/site-packages/neovim/msgpack_rpc/session.py", line 177, in handler
    rv = self._request_cb(name, args)
  File "/Users/cmav/miniconda2/lib/python2.7/site-packages/neovim/api/common.py", line 237, in filter_request_cb
    walk(self._in, args, self, name, 'request'))
  File "/Users/cmav/miniconda2/lib/python2.7/site-packages/neovim/plugin/host.py", line 65, in _on_request
    rv = handler(*args)
  File "/usr/local/Cellar/neovim/0.1.0/share/nvim/runtime/autoload/provider/script_host.py", line 76, in python_execut
e
    exec(script, self.module.__dict__)
  File "<string>", line 32, in <module>
NameError: name 'vim' is not defined
Error detected while processing function <SNR>25_SetCondaPlainPath:
line   35:
E121: Undefined variable: l:temppath
E15: Invalid expression: l:temppath

and then neovim segfaults. Any idea on how to fix this?

Enable root conda environment

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.

Issue with Jedi after install vim-condo

Hi, I have this issue after install vim-conda. It seems like it is not compatible with jedi-vim?

Error detected while processing function jedi#init_python[4]..<SNR>41_init_python[27]..jedi#setup_python_imports: line 25: Traceback (most recent call last): File "<string>", line 1, in <module> File "<string>", line 8, in <module> File "/Users/kiennguyen/.vim/bundle/jedi-vim/pythonx/jedi_vim_debug.py", line 5, in <module> from jedi_vim import PythonToVimStr File "/Users/kiennguyen/.vim/bundle/jedi-vim/pythonx/jedi_vim.py", line 112, in <module> import jedi File "/Users/kiennguyen/.vim/bundle/jedi-vim/pythonx/jedi/jedi/__init__.py", line 41, in <module> from jedi.api import Script, Interpreter, set_debug_function, \ File "/Users/kiennguyen/.vim/bundle/jedi-vim/pythonx/jedi/jedi/api/__init__.py", line 21, in <module> from jedi import debug File "/Users/kiennguyen/.vim/bundle/jedi-vim/pythonx/jedi/jedi/debug.py", line 23, in <module> from colorama import Fore, init File "/Users/kiennguyen/anaconda3/lib/python3.6/site-packages/colorama/__init__.py", line 2, in <module> from .initialise import init, deinit, reinit, colorama_text File "/Users/kiennguyen/anaconda3/lib/python3.6/site-packages/colorama/initialise.py", line 6, in <module> from .ansitowin32 import AnsiToWin32 File "/Users/kiennguyen/anaconda3/lib/python3.6/site-packages/colorama/ansitowin32.py", line 7, in <module> from .winterm import WinTerm, WinColor, WinStyle File "/Users/kiennguyen/anaconda3/lib/python3.6/site-packages/colorama/winterm.py", line 2, in <module> from . import win32 File "/Users/kiennguyen/anaconda3/lib/python3.6/site-packages/colorama/win32.py", line 8, in <module> import ctypes File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 555, in <module> _reset_cache() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/__init__.py", line 279, in _reset_cache CFUNCTYPE(c_int)(lambda: None)

Improve documentation page for vim

The documentation file vim-conda.txt is almost empty, and should be populated with something relevant. Even very basic documentation, like copying some info from the README would be great.

Massive error log on startup

I am using Pathogen and Vim 7.4 (patch 1...1689) and Anaconda w/ Python 3.
vim-conda 838f582

$ vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 16 2016 10:50:38)
Included patches: 1-1689
Modified by [email protected]
Compiled by [email protected]
Huge version with GTK2 GUI.  Features included (+) or not (-):
+acl             +farsi           +mouse_netterm   +tag_binary
+arabic          +file_in_path    +mouse_sgr       +tag_old_static
+autocmd         +find_in_path    -mouse_sysmouse  -tag_any_white
+balloon_eval    +float           +mouse_urxvt     +tcl
+browse          +folding         +mouse_xterm     +terminfo
++builtin_terms  -footer          +multi_byte      +termresponse
+byte_offset     +fork()          +multi_lang      +textobjects
+channel         +gettext         -mzscheme        +timers
+cindent         -hangul_input    +netbeans_intg   +title
+clientserver    +iconv           +packages        +toolbar
+clipboard       +insert_expand   +path_extra      +user_commands
+cmdline_compl   +job             +perl            +vertsplit
+cmdline_hist    +jumplist        +persistent_undo +virtualedit
+cmdline_info    +keymap          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       -python          +vreplace
+cscope          +lispindent      +python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con_gui  +lua             +rightleft       +writebackup
+diff            +menu            +ruby            +X11
+digraphs        +mksession       +scrollbind      -xfontset
+dnd             +modify_fname    +signs           +xim
-ebcdic          +mouse           +smartindent     +xsmp_interact
+emacs_tags      +mouseshape      +startuptime     +xterm_clipboard
+eval            +mouse_dec       +statusline      -xterm_save
+ex_extra        +mouse_gpm       -sun_workshop    +xpm
+extra_search    -mouse_jsbterm   +syntax          
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK  -pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2 -Wdate-time  -g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-x11-2.0 -lgdk-x11-2.0 -lpangocairo-1.0 -latk-1.0 -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lpangoft2-1.0 -lpango-1.0 -lgobject-2.0 -lglib-2.0 -lfontconfig -lfreetype -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE  -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl  -L/usr/lib -llua5.2 -Wl,-E  -fstack-protector-strong -L/usr/local/lib  -L/usr/lib/x86_64-linux-gnu/perl/5.22/CORE -lperl -ldl -lm -lpthread -lcrypt  -L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -lpython3.5m -lpthread -ldl -lutil -lm -L/usr/lib/x86_64-linux-gnu -ltcl8.6 -ldl -lz -lpthread -lieee -lm -lruby-2.3 -lpthread -lgmp -ldl -lcrypt -lm
hholst@fb-hholst3:~$ which python
/home/hholst/anaconda3/bin/python
hholst@fb-hholst3:~$ which python2
/usr/bin/python2
hholst@fb-hholst3:~$ which python3
/home/hholst/anaconda3/bin/python3
hholst@fb-hholst3:~$ python --version
Python 3.5.1 :: Anaconda custom (64-bit)
hholst@fb-hholst3:~$ 
E133: :return not inside a function
line   20:
E488: Trailing characters:         # Needed to avoid
line   21:
E488: Trailing characters:         # When launching gvim.exe from a CMD shell. (gvim from icon seems
line   22:
E488: Trailing characters:         # fine!?)
line   23:
E488: Trailing characters:         # See also: http://bugs.python.org/issue3905
line   24:
E488: Trailing characters:         # stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
line   25:
E492: Not an editor command:         stdin=PIPE, stderr=PIPE)
line   28:
E492: Not an editor command: def vim_conda_runpyshell(cmd):
line   29:
E133: :return not inside a function
line   30:
E492: Not an editor command:         executable=os.getenv('SHELL'),
line   31:
E492: Not an editor command:         stdin=PIPE, stderr=PIPE)
line   34:
E492: Not an editor command: def get_conda_info_dict():
line   36:
E492: Not an editor command:     {
line   42:
E492: Not an editor command:       ],
line   55:
E492: Not an editor command:       ],
line   58:
E492: Not an editor command:       ],
line   62:
E492: Not an editor command:       ],
line   71:
E492: Not an editor command:     }
line   73:
E492: Not an editor command:     output = vim_conda_runshell('conda info --json')
line   74:
E133: :return not inside a function
line   77:
E492: Not an editor command: def insert_system_py_sitepath():
line   79:
E492: Not an editor command:     embedded Python's sys.path. This is for Jedi-vim code completion. """
line   80:
E492: Not an editor command:     cmd = "import site, sys, os; sys.stdout.write(os.path.pathsep.join(site.getsitepackages()))"
line   81:
E33: No previous substitute regular expression
line   82:
E488: Trailing characters:     # The following causes errors. Jedi vim imports e.g. hashlib
line   83:
E488: Trailing characters:     # from the stdlib, but it we've added a different stdlib to the
line   84:
E488: Trailing characters:     # embedded sys.path, jedi loads the wrong one, causing errs.
line   85:
E488: Trailing characters:     # Looks like we should only load site-packages.
line   86:
E488: Trailing characters:     # if len(sitedirs) > 0:
line   87:
E488: Trailing characters:     #     libdir = os.path.dirname(sitedirs[0])
line   88:
E488: Trailing characters:     #     if libdir not in sys.path:
line   89:
E488: Trailing characters:     #         sys.path.insert(0, libdir)
line   90:
E121: Undefined variable: sitedirs
E15: Invalid expression: sitedirs:
line  420:
E171: Missing :endif
Press ENTER or type command to continue

Had Error: "UnboundLocalError: local variable 'current_env' referenced before assignment" at line 336 in conda_change_env, fixed it myself, here is what I did.

So vim was throwing me this error;

condavimbugfixed

You can reproduce it using the following steps:
1). Switch to any other conda environment,
2). Switch back to the original "Anaconda3" environment and finally;
3). Attempt to switch to any other environment.

I just added the following code around line 330ish:

    default_prefix = get_default_prefix()
  
    # my addition:
    current_env = root_prefix

    for key, value in envnames.items():
        if value == default_prefix:
            current_env = key
            break

and it fixed the issue.

I am just popping in to give you a heads up. Great plugin by the way!

python 2 & 3 compatibility

I created a fork to add compatiblity for both flavors of python. It could use some more testing since I don't use python 2 much any more.

Let me know if you'd like a pull request.

Thanks for the great script. I learned alot updating it for my needs.

Add the stdlib path for Python 3

Currently we are adding the site-packages for an activated env, but it seems we really also need to add the stdlib path, otherwise py3-specific stuff in the stdlib isn't found.

how to set CONDA_EXE on MS Windows?

where and how exactly should I set this variable on windows

I have already tried:
C:\Users\adrian\Miniconda3\Scripts\conda.exe
/c/Users/adrian/Miniconda3/Scripts/conda.exe

in System Properieties > Environment Variables

and in neovim running
:echo $CONDA_EXE
it shows the set path

but when I try
:CondaChangeEnv
I still get:

RuntimeError: $CONDA_EXE is not set to a valid conda executable ($CONDA_EXE='$CONDA_EXE')

msg_suppress not defined

If I start vim and the CONDA_DEFAULT_ENV environment variable is not defined, when I attempt to activate an environment using :CondaChangeEnv, I get an error message complaining that the global variable msg_suppress is not defined in the conda_activate function. Looking at the vim-conda.vim file, I see that this is true - the variable is only set if CONDA_DEFAULT_ENV is already set. The msg_suppress global variable needs to be set no matter what.

How to set default conda env $CONDA_DEFAULT_ENV?

First off cool plug-in! Thanks for creating it.

I would like to set a default conda env

I tried adding the line:
export CONDA_DEFAULT_ENV="root"

in .bashrc and .zshrc but that didn't work

I also tried adding:
let g.CONDA_DEFAULT_ENV="root"
even though I didn't think it would work.

Is there a way to set a default env so that I don't have to select an env when I start neovim?

Set environment in vimrc

Hi, I wonder if there is a way to setup the environment from the start in vimrc or at least map key for choosing a particular env without choosing one with tab each time?

Change sys.path to include site-packages of the cmdline Python

In my vim setup, Python is fully embedded, meaning that both pythonXY.dll and pythonXY.zip (i.e. a zipped archive of the stdlib) are located in the same folder as the vim executable. Thus, by default, inside vim, running :py import sys; print sys.path will not include the site-packages folder of the python that will execute my code on the command line, i.e via :!python myfile.py. The way jedi-vim works is to the the sys.path of the internal python for code completion. Therefore, I need to modify sys.path in order to include the site-packages of the cmdline python.

This change is already made when changing conda envs (as per this plugin). This issue is only for the startup case:

  • before a conda env change has been made, and
  • the cmdline Python is different to the embedded Python, and
  • the sys.path of the embedded Python does not include the site-packages folder of the cmdline Python.

Python 3 support?

Is Python 3 not supported? I am trying to see if it will work by updating the print calls and changing the code in SetCondaPlainPath() to transform the conda info string to unicode before parsing it as json, but I keep failing.

Source conda.sh on startup?

First of all, thanks for creating this plugin!

When I run vim from a terminal, everything works as it should. However, when I open vim directly through my window manager (with a key binding to konsole -e vim), I get the following error if I run :CondaChangeEnv:

Error detected while processing function <SNR>37_CondaChangeEnv:
line    2:
Traceback (most recent call last):
  File "/home/david/.vim/plugged/vim-conda/plugin/vimconda.py", line 54, in func
    v = self.cache[key]
KeyError: (('$CONDA_EXE info --json',), ())
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/david/.vim/plugged/vim-conda/plugin/vimconda.py", line 319, in conda_change_env
    envs = get_envs()
  File "/home/david/.vim/plugged/vim-conda/plugin/vimconda.py", line 161, in get_envs
    return get_conda_info_dict()['envs']
  File "/home/david/.vim/plugged/vim-conda/plugin/vimconda.py", line 211, in get_conda_info_dict
    output = vim_conda_runshell('$CONDA_EXE info --json')
  File "/home/david/.vim/plugged/vim-conda/plugin/vimconda.py", line 58, in func
    v = self.cache[key] = f(*args, **kwargs), time.time()
  File "/home/david/.vim/plugged/vim-conda/plugin/vimconda.py", line 148, in vim_conda_runshell
    return check_output(cmd, shell=True, executable=os.getenv('SHELL'), stdin=PIPE, stderr=PIPE).decode('utf-8')
  File "/home/david/anaconda3/lib/python3.8/subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "/home/david/anaconda3/lib/python3.8/subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '$CONDA_EXE info --json' returned non-zero exit status 1.

After experimenting a bit, I think the issue is that ~/anaconda3/etc/profile.d/conda.sh isn't being sourced - when I run :! conda activate, I get CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'., but if I source conda.sh first, it works. (However, as vim starts a new shell for each command, I still can't run :CondaChangeEnv, so it's possible there's something else that I'm missing.)

My question is, how can I configure vim to always source the shell script on startup? (I tried googling this and checking the help pages, but didn't have much luck.) Also, would it be possible to add a check for this, to make the error message a bit less cryptic? Thanks for your help!

Activating the environment that was active during vim startup fails

Hey there, thanks for the great plugin!

I have one issue. When I start vim with an active conda environment, that conda envirnoment is not listed when running CondaChangeEnv. Which means that when I switch to another environment, I am unable to switch back to the original one.

Can anyone reproduce this issue?

Bug: plugin.vim should import vim

Currently plugin.vim relies on some other script importing the python vim plugin. To fix this just add

import vim

To the top imports in the plugin.

Showing name Error. I have installed spacevim and anaconda as well, but I don't know why this error is showing.

Error detected while processing /home/harsh/.cache/vimfiles/.cache/vimrc/.dein/plugin/vim-conda.vim:
line 42:
Traceback (most recent call last):
File "", line 1, in
File "/home/harsh/.cache/vimfiles/.cache/vimrc/.dein/plugin/vimconda.py", line 15, in
from subprocess import check_output, PIPE
File "/home/harsh/anaconda3/lib/python3.7/subprocess.py", line 139, in
import _posixsubprocess
ImportError: /home/harsh/anaconda3/lib/python3.7/lib-dynload/_posixsubprocess.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _Py_write_norais
Error detected while processing function 150_SetCondaPlainPath:
line 1:
Traceback (most recent call last):
File "", line 1, in
NameError: name 'vimconda' is not defined
line 2:
E121: Undefined variable: l:temppath
E15: Invalid expression: l:temppath
Error detected while processing /home/harsh/.cache/vimfiles/.cache/vimrc/.dein/plugin/vim-conda.vim:
line 124:
Traceback (most recent call last):
File "", line 1, in
NameError: name 'vimconda' is not defined

The Issue about :CondaChangeEnv

Thanks for you greate work. But I have a problem when I write the configuration file of nvim.
My computer is Mac OS M1
My config file is :
call plug#begin()

Plug 'octol/vim-cpp-enhanced-highlight'

" 安装和启用插件
" vim-conda:用于集成 Anaconda
Plug 'cjrh/vim-conda'
let g:python3_host_prog = expand("/Users/gaohaitao/opt/anaconda3/envs/pytorch/bin/python")

let g:conda_python3_executable = expand("/Users/gaohaitao/opt/anaconda3/envs/traffic/bin/python")

let g:conda_executable = expand('/Users/gaohaitao/opt/anaconda3/bin/conda')

" 设置CondaChangeEnv命令为自动加载
augroup conda_autogroup
autocmd!
autocmd VimEnter * CondaChangeEnv
augroup END

call plug#end()
But appear the ERROR:
处理 VimEnter 自动命令 "*"..function 8_CondaChangeEnv[2]..provider#python3#Call 时发生错误:
第 18 行:
Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
File "", line 1, in
File "/Users/gaohaitao/.local/share/nvim/plugged/vim-conda/plugin/vimconda.py", line 361, in conda_change_env
envs = get_envs()
File "/Users/gaohaitao/.local/share/nvim/plugged/vim-conda/plugin/vimconda.py", line 187, in get_envs
envs = get_conda_info_dict()["envs"]
File "/Users/gaohaitao/.local/share/nvim/plugged/vim-conda/plugin/vimconda.py", line 242, in get_conda_info_dict
output = vim_conda_runshell(conda_exe + " info --json")
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

I have tried a lot of methods but they didn't work. Could you help me?

vim-conda is not compatible with the latest conda env activation mechanism

Starting from Conda 4.4, the recommended way of activating conda env has been changed.

Now when I execute CondaChangeEnv command with the latest setup (setting . /opt/conda/etc/profile.d/conda.sh in .bashrc). The vim command complains as follows:

~/.conda/envs/vim_test/lib/python3.6/subprocess.py in check_output(timeout, *popenargs, **kwargs)
    334 
    335     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 336                **kwargs).stdout
    337 
    338 

~/.conda/envs/vim_test/lib/python3.6/subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    416         if check and retcode:
    417             raise CalledProcessError(retcode, process.args,
--> 418                                      output=stdout, stderr=stderr)
    419     return CompletedProcess(process.args, retcode, stdout, stderr)
    420 

CalledProcessError: Command 'conda info --json' returned non-zero exit status 127.

Changing back to the old export PATH=... solves the above issue. But would it be possible to be compatible with latest conda? Thank you!

Startup speed (on Windows)

The vim-conda plugin takes way too long to load, 400-500 ms based on --startuptime timings. The subprocess calls are surely a big chunk, but we can be smarter in how the work gets done.

I'm also thinking it might be a good idea to have a continuously-running process for querying conda things, rather than starting up a subprocess each time.

Suppress Message on Startup

Is there a way to suppress the following message that is printed on startup -

Conda env deactivated.
Activated env: py33
Press ENTER or type command to continue

It will help, if there was an option that I can define in the .vimrc file to hide/display the message.

E887: Sorry, this command is disabled, the Python's site module could not be loaded.

After I issue the command:

$ brew linkapps

(forgot to mention the apps I want to link above )

Now I every time I launch vim or mvim I get:

$ mvim
~
$ Error detected while processing /Users/apollotang/.vim/plugged/vim-conda/plugin/vim-conda.vim:
line   40:
E887: Sorry, this command is disabled, the Python's site module could not be loaded.
line   41:
E887: Sorry, this command is disabled, the Python's site module could not be loaded.
line   42:
E887: Sorry, this command is disabled, the Python's site module could not be loaded.
Error detected while processing function <SNR>60_SetCondaPlainPath:
line    1:
E887: Sorry, this command is disabled, the Python's site module could not be loaded.
line    2:
E121: Undefined variable: l:temppath
E15: Invalid expression: l:temppath
Error detected while processing /Users/apollotang/.vim/plugged/vim-conda/plugin/vim-conda.vim:
line  124:
E887: Sorry, this command is disabled, the Python's site module could not be loaded.

I am new to python, have no idea how to fix this please help :(

my conda info looks like this:

$ conda info -e
# conda environments:
#
py27                     /Users/apollotang/opt/local/anaconda2/envs/py27
py36                     /Users/apollotang/opt/local/anaconda2/envs/py36
root                  *  /Users/apollotang/opt/local/anaconda2

$ which python
/Users/apollotang/opt/local/anaconda2/bin/python

$ python << EOF
> import sys;
> print(sys.version);
> EOF
2.7.13 |Anaconda 2.5.0 (x86_64)| (default, Dec 20 2016, 23:05:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)]

and my vim info look like this:

$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Aug  9 2017 05:34:38)
MacOS X (unix) version
Included patches: 1-893
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl             +file_in_path    +mouse_sgr       +tag_old_static
+arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
+autocmd         +float           +mouse_urxvt     -tcl
-balloon_eval    +folding         +mouse_xterm     +termguicolors
-browse          -footer          +multi_byte      +terminal
++builtin_terms  +fork()          +multi_lang      +terminfo
+byte_offset     -gettext         -mzscheme        +termresponse
+channel         -hangul_input    +netbeans_intg   +textobjects
+cindent         +iconv           +num64           +timers
-clientserver    +insert_expand   +packages        +title
+clipboard       +job             +path_extra      -toolbar
+cmdline_compl   +jumplist        +perl            +user_commands
+cmdline_hist    +keymap          +persistent_undo +vertsplit
+cmdline_info    +lambda          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      +startuptime     -xpm
+eval            +mouse_dec       +statusline      -xsmp
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_clipboard
+extra_search    -mouse_jsbterm   +syntax          -xterm_save
+farsi           +mouse_netterm   +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/share/vim"
Compilation: clang -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: clang   -L. -fstack-protector -L/usr/local/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/readline/lib  -L/usr/local/lib -o vim        -lncurses -liconv -framework Cocoa   -mmacosx-version-min=10.12 -fstack-protector-strong -L/usr/local/lib  -L/usr/local/Cellar/perl/5.26.0/lib/perl5/5.26.0/darwin-thread-multi-2level/CORE -lperl -lm -lutil -lc -F/usr/local/opt/python/Frameworks -framework Python   -lruby.2.4.1 -lobjc

from the above I can tell the vim is trying to read python from

/usr/local/opt/python/Frameworks

Which is obviously wrong, because it trying to get the python via homebrew instead of conda:

$ /usr/local/opt/python/bin/python
Python 2.7.11 (default, Dec 26 2015, 17:47:53)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Would you please help if I can get vim-conda working again ?
Thanks

Startup errors in Neovim on windows

Hi,

I get a whole bunch of errors when starting Neovim, or forcing plugins to update:

Error invoking 'python_execute' on channel 3 (python3-script-host):
Traceback (most recent call last):
  File "C:\Users\[my username]\.vim\plugged\vim-conda\plugin\vimconda.py", line 54, in func
    v = self.cache[key]
KeyError: (('import site, sys, os; sys.stdout.write(os.path.pathsep.join(site.getsitepackages()))',), ())

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Users\[my username]\.vim\plugged\vim-conda\plugin\vimconda.py", line 216, in insert_system_py_sitepath
    sitedirs = vim_conda_runpyshell(cmd)
  File "C:\Users\[my username]\.vim\plugged\vim-conda\plugin\vimconda.py", line 58, in func
    v = self.cache[key] = f(*args, **kwargs), time.time()
  File "C:\Users\[my username]\.vim\plugged\vim-conda\plugin\vimconda.py", line 151, in vim_conda_runpyshell
    return check_output('python -c "{}"'.format(cmd),
  File "C:\Users\[my username]\Anaconda3\envs\neovim_python3\lib\subprocess.py", line 411, in check_output
    return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
  File "C:\Users\[my username]\Anaconda3\envs\neovim_python3\lib\subprocess.py", line 512, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command 'python -c "import site, sys, os; sys.stdout.write(os.path.pathsep.join(site.getsitepackages()))"' returned non-zero exit status 9009.

I'm running Neovim 0.4.3 with the nvim-qt wrapper on Windows 10

I've set up environments for python 2 and 3 with pynvim in each, and configured python_host_prog and python3_host_prog - :checkhealth provider says both are OK:

## Python 2 provider (optional)
  - INFO: Using: g:python_host_prog = "C:\Users\[my username]/Anaconda3/envs/neovim_python2/python"
  - INFO: Executable: C:\Users\[my username]\Anaconda3\envs\neovim_python2\python
  - INFO: Python version: 2.7.15
  - INFO: pynvim version: 0.4.1
  - OK: Latest pynvim is installed.

## Python 3 provider (optional)
  - INFO: Using: g:python3_host_prog = "C:\Users\[my username]/Anaconda3/envs/neovim_python3/python"
  - INFO: Executable: C:\Users\[my username]\Anaconda3\envs\neovim_python3\python
  - INFO: Python version: 3.8.3
  - INFO: pynvim version: 0.4.1
  - OK: Latest pynvim is installed.

How can I get this working?

Kind regards,

Sandy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.