Set python virtualenv in vim -
i use vim coding , python coding in particular. want execute current buffer python interpreter. (for example run unittests), :!python % <enter>
this scenatio work works fine global python, want run virtualenv python instead. how enable virtualenv within vim? possible switch virtualenv on runtime?
i'm using macvim
here's use (sorry highlighting screwy).
" function activate virtualenv in embedded interpreter " omnicomplete , other things that. function loadvirtualenv(path) let activate_this = a:path . '/bin/activate_this.py' if getftype(a:path) == "dir" && filereadable(activate_this) python << eof import vim activate_this = vim.eval('l:activate_this') execfile(activate_this, dict(__file__=activate_this)) eof endif endfunction " load 'stable' virtualenv if 1 exists in ~/.virtualenv let defaultvirtualenv = $home . "/.virtualenvs/stable" " attempt load virtualenv if defaultvirtualenv " exists, , aren't running virtualenv active. if has("python") if empty($virtual_env) && getftype(defaultvirtualenv) == "dir" call loadvirtualenv(defaultvirtualenv) endif endif
note need have macvim compiled against python using virtualenv, e.g. if downloaded python 2.7 python.org should recompile macvim using --with-python-config-dir=/library/frameworks/python.framework/versions/2.7/lib/python2.7/config
argument ./configure
.
hope helps!
edit: 1 note of attribution: lot of detective work went writing little ditty done this blogger, , deserves of credit.
Comments
Post a Comment