davidhalter / jedi-vim

Using the jedi autocompletion library for VIM.
MIT License
5.28k stars 370 forks source link

Jedi vim not working with python 3.6 venv + SOLUTION #704

Closed ViktorBarzin closed 7 years ago

ViktorBarzin commented 7 years ago

Issue

Some prerequisites:

So the issue is when creating a virtual enviorment with python 3.6 and installing any 3rd party library, jedi vim's omni completion does not show any results.

Steps to reproduce

  1. Make sure you have virtual enviorment activated and with python 3.6
  2. pip install django
  3. open a python file vim a.py
  4. start typing from django. and after the '.' activate omni completion. It should say no results found.

Solution

Below you can see the output of redir @+> | silent verb JediDebugInfo | redir END So let me walk you through the solution I found. Actually there a couple of walkarounds I will show you because I believe this problem is really hard to google (at least for me it was) and is kinda tricky to find.

Let's begin. Open up a .py file and enter the command JediDebugInfo. You will see information about jedi vim. The part we are interested in is sys_path. If you look closely at the virtual enviorment path you will notice something like this /username/.virtualenvs/name-of-env/lib/**python3.5**/site-packages. Now if you go to the lib folder of the enviorment you will notice that the next folder is named python3.6 not python3.5. So it cannot find the site packages of the enviorment therefore omni completion does not work.

Now for the impatient, the easy solution is just to rename the folder from python3.6 to python3.5. Everything will work just fine. The problem with that is that you need to do this for every virtual env you make with python3.6 if you want omni completion.

This solution was not good enough for me so I went on digging. It is obvious that if I make my env with python 3.6 and the sys_path contains python 3.5 it means that something is generating this path and is hard coded somewhere(thank god it's not binary).Now you hit another major problem because you can't google that as well. Here comes the part you'll thank me for - The method that is responsible for generating the sys_path under virtual env is located in ~/.vim/bundle/jedi-vim/jedi/jedi/evaluate/sys_path.py line 15. Now you can write you custom code to detect python 3.6 envs and site-packages folders. Add the paths you want as a list of strings on line 24 where the return statement is.

However, both solutions are just walkarounds. The problem originates because jedi-vim uses the vim default intepreter which if compiled with +python3 is python 3.5.2.

Hope this get fixed and someone who has had this problem finds my solutions useful :)

Output of “:verbose JediDebugInfo”

Jedi-vim debug information

Using Python version: 3

Settings
g:jedi#force_py_version = 3 (default: 'auto')
g:jedi#popup_select_first = 0 (default: 1)
g:jedi#popup_on_dot = 0 (default: 1)
g:jedi#usages_command = '<leader>z' (default: '<leader>n')

  omnifunc=jedi#completions
    Last set from ~/.vimrc
  completeopt=longest,menuone
    Last set from ~/.vimrc

:version


VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 07 2017 03:33:23)
Included patches: 1-197, 322, 377-378
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by pkg-vim-maintainers@lists.alioth.debian.org
Huge version with GTK3 GUI.  Features included (+) or not (-):
+acl             +cmdline_hist    -ebcdic          +gettext         +listcmds        +mouse_sgr       +persistent_undo +smartindent     +textobjects     +wildmenu
+arabic          +cmdline_info    +emacs_tags      -hangul_input    +localmap        -mouse_sysmouse  +postscript      +startuptime     +timers          +windows
+autocmd         +comments        +eval            +iconv           +lua             +mouse_urxvt     +printer         +statusline      +title           +writebackup
+balloon_eval    +conceal         +ex_extra        +insert_expand   +menu            +mouse_xterm     +profile         -sun_workshop    +toolbar         +X11
+browse          +cryptv          +extra_search    +job             +mksession       +multi_byte      -python          +syntax          +user_commands   -xfontset
++builtin_terms  +cscope          +farsi           +jumplist        +modify_fname    +multi_lang      +python3         +tag_binary      +vertsplit       +xim
+byte_offset     +cursorbind      +file_in_path    +keymap          +mouse           -mzscheme        +quickfix        +tag_old_static  +virtualedit     +xpm
+channel         +cursorshape     +find_in_path    +lambda          +mouseshape      +netbeans_intg   +reltime         -tag_any_white   +visual          +xsmp_interact
+cindent         +dialog_con_gui  +float           +langmap         +mouse_dec       +num64           +rightleft       +tcl             +visualextra     +xterm_clipboard
+clientserver    +diff            +folding         +libcall         +mouse_gpm       +packages        +ruby            +termguicolors   +viminfo         -xterm_save
+clipboard       +digraphs        -footer          +linebreak       -mouse_jsbterm   +path_extra      +scrollbind      +terminfo        +vreplace        
+cmdline_compl   +dnd             +fork()          +lispindent      +mouse_netterm   +perl            +signs           +termresponse    +wildignore      
   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"
       defaults file: "$VIMRUNTIME/defaults.vim"
    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-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -Wdate-time  -g -O2 -fdebug-prefix-map=/build/vim-yUSlYU/vim-8.0.0197=. -fstack-protector-strong -Wformat -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
Linking: gcc   -L. -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic -Wl,-E  -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -o vim   -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 -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.24/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     

:messages

Messages maintainer: Bram Moolenaar <Bram@vim.org>
:scriptnames ``` 1: /usr/share/vim/vimrc 2: /usr/share/vim/vim80/debian.vim 3: ~/.vimrc 4: ~/.vim/colors/wombat256mod.vim 5: /usr/share/vim/vim80/ftoff.vim 6: /usr/share/vim/vim80/filetype.vim 7: /usr/share/vim/vim80/ftplugin.vim 8: /usr/share/vim/vim80/indent.vim 9: /usr/share/vim/vim80/syntax/syntax.vim 10: /usr/share/vim/vim80/syntax/synload.vim 11: /usr/share/vim/vim80/syntax/syncolor.vim 12: ~/.vim/autoload/pathogen.vim 13: ~/.vim/bundle/xptemplate/ftdetect/xptemplate.detect.vim 14: ~/.vim/bundle/xptemplate/ftdetect/xptlog.detect.vim 15: ~/.vim/bundle/AutoComplPop/plugin/acp.vim 16: ~/.vim/bundle/AutoComplPop/autoload/acp.vim 17: ~/.vim/bundle/ctrlp.vim/plugin/ctrlp.vim 18: ~/.vim/bundle/ctrlp.vim/autoload/ctrlp/mrufiles.vim 19: ~/.vim/bundle/emmet-vim/plugin/emmet.vim 20: ~/.vim/bundle/jedi-vim/plugin/jedi.vim 21: ~/.vim/bundle/nerdtree/plugin/NERD_tree.vim 22: ~/.vim/bundle/nerdtree/autoload/nerdtree.vim 23: ~/.vim/bundle/nerdtree/lib/nerdtree/path.vim 24: ~/.vim/bundle/nerdtree/lib/nerdtree/menu_controller.vim 25: ~/.vim/bundle/nerdtree/lib/nerdtree/menu_item.vim 26: ~/.vim/bundle/nerdtree/lib/nerdtree/key_map.vim 27: ~/.vim/bundle/nerdtree/lib/nerdtree/bookmark.vim 28: ~/.vim/bundle/nerdtree/lib/nerdtree/tree_file_node.vim 29: ~/.vim/bundle/nerdtree/lib/nerdtree/tree_dir_node.vim 30: ~/.vim/bundle/nerdtree/lib/nerdtree/opener.vim 31: ~/.vim/bundle/nerdtree/lib/nerdtree/creator.vim 32: ~/.vim/bundle/nerdtree/lib/nerdtree/flag_set.vim 33: ~/.vim/bundle/nerdtree/lib/nerdtree/nerdtree.vim 34: ~/.vim/bundle/nerdtree/lib/nerdtree/ui.vim 35: ~/.vim/bundle/nerdtree/lib/nerdtree/event.vim 36: ~/.vim/bundle/nerdtree/lib/nerdtree/notifier.vim 37: ~/.vim/bundle/nerdtree/autoload/nerdtree/ui_glue.vim 38: ~/.vim/bundle/nerdtree/nerdtree_plugin/exec_menuitem.vim 39: ~/.vim/bundle/nerdtree/nerdtree_plugin/fs_menu.vim 40: ~/.vim/bundle/supertab/plugin/supertab.vim 41: ~/.vim/bundle/syntastic/plugin/syntastic/autoloclist.vim 42: ~/.vim/bundle/syntastic/plugin/syntastic/balloons.vim 43: ~/.vim/bundle/syntastic/plugin/syntastic/checker.vim 44: ~/.vim/bundle/syntastic/plugin/syntastic/cursor.vim 45: ~/.vim/bundle/syntastic/plugin/syntastic/highlighting.vim 46: ~/.vim/bundle/syntastic/plugin/syntastic/loclist.vim 47: ~/.vim/bundle/syntastic/plugin/syntastic/modemap.vim 48: ~/.vim/bundle/syntastic/plugin/syntastic/notifiers.vim 49: ~/.vim/bundle/syntastic/plugin/syntastic/registry.vim 50: ~/.vim/bundle/syntastic/plugin/syntastic/signs.vim 51: ~/.vim/bundle/syntastic/plugin/syntastic.vim 52: ~/.vim/bundle/syntastic/autoload/syntastic/util.vim 53: ~/.vim/bundle/vim-airline/plugin/airline.vim 54: ~/.vim/bundle/vim-airline/autoload/airline.vim 55: ~/.vim/bundle/vim-airline/autoload/airline/init.vim 56: ~/.vim/bundle/vim-airline/autoload/airline/parts.vim 57: ~/.vim/bundle/vim-commentary/plugin/commentary.vim 58: ~/.vim/bundle/vim-powerline/plugin/Powerline.vim 59: ~/.vim/bundle/vim-surround/plugin/surround.vim 60: ~/.vim/bundle/vim-virtualenv/plugin/virtualenv.vim 61: ~/.vim/bundle/vim-virtualenv/autoload/virtualenv.vim 62: ~/.vim/bundle/xptemplate/plugin/debug.vim 63: ~/.vim/bundle/xptemplate/autoload/XPT.vim 64: ~/.vim/bundle/xptemplate/plugin/xpmark.vim 65: ~/.vim/bundle/xptemplate/plugin/xptemplate.conf.vim 66: ~/.vim/bundle/xptemplate/autoload/xpt/option/cwd_snippet.vim 67: ~/.vim/bundle/xptemplate/autoload/xpt/once.vim 68: ~/.vim/bundle/xptemplate/autoload/xpt/option/lib_filter.vim 69: ~/.vim/bundle/xptemplate/autoload/xpt/util.vim 70: ~/.vim/bundle/xptemplate/autoload/xpt/debug.vim 71: ~/.vim/bundle/xptemplate/plugin/xpopup.vim 72: ~/.vim/bundle/xptemplate/plugin/xpreplace.vim 73: ~/.vim/bundle/xptemplate/plugin/xpt.plugin.highlight.vim 74: ~/.vim/bundle/xptemplate/plugin/xptemplate.vim 75: ~/.vim/bundle/xptemplate/autoload/xpt/rctx.vim 76: ~/.vim/bundle/xptemplate/autoload/xpt/flt.vim 77: ~/.vim/bundle/xptemplate/plugin/xptemplate.parser.vim 78: /usr/share/vim/vim80/plugin/getscriptPlugin.vim 79: /usr/share/vim/vim80/plugin/gzip.vim 80: /usr/share/vim/vim80/plugin/logiPat.vim 81: /usr/share/vim/vim80/plugin/manpager.vim 82: /usr/share/vim/vim80/plugin/matchparen.vim 83: /usr/share/vim/vim80/plugin/netrwPlugin.vim 84: /usr/share/vim/vim80/plugin/rrhelper.vim 85: /usr/share/vim/vim80/plugin/spellfile.vim 86: /usr/share/vim/vim80/plugin/tarPlugin.vim 87: /usr/share/vim/vim80/plugin/tohtml.vim 88: /usr/share/vim/vim80/plugin/vimballPlugin.vim 89: /usr/share/vim/vim80/plugin/zipPlugin.vim 90: ~/.vim/ftplugin/python_editing.vim 91: ~/.vim/bundle/jedi-vim/ftplugin/python/jedi.vim 92: ~/.vim/bundle/jedi-vim/autoload/jedi.vim 93: ~/.vim/bundle/xptemplate/ftplugin/python/python.xpt.vim 94: ~/.vim/bundle/xptemplate/autoload/xpt/parser.vim 95: ~/.vim/bundle/xptemplate/autoload/xpt/buf.vim 96: ~/.vim/bundle/xptemplate/autoload/xpt/msvr.vim 97: ~/.vim/bundle/xptemplate/autoload/xpt/settingswitch.vim 98: ~/.vim/bundle/xptemplate/autoload/xpt/snipfile.vim 99: ~/.vim/bundle/xptemplate/autoload/xpt/priority.vim 100: ~/.vim/bundle/xptemplate/autoload/xpt/ftscope.vim 101: ~/.vim/bundle/xptemplate/ftplugin/_common/common.xpt.vim 102: ~/.vim/bundle/xptemplate/ftplugin/_common/inlineComplete.xpt.vim 103: ~/.vim/bundle/xptemplate/ftplugin/_common/common.bracketcmpl.xpt.vim 104: ~/.vim/bundle/xptemplate/ftplugin/_common/common.path.xpt.vim 105: ~/.vim/bundle/xptemplate/autoload/xpt/snipfunction.vim 106: ~/.vim/bundle/xptemplate/autoload/xpt/snipfuncs/actionhelper.vim 107: ~/.vim/bundle/xptemplate/autoload/xpt/snipfuncs/evalhelper.vim 108: ~/.vim/bundle/xptemplate/ftplugin/_comment/singleDouble.xpt.vim 109: ~/.vim/bundle/xptemplate/ftplugin/_comment/singleSign.xpt.vim 110: ~/.vim/bundle/xptemplate/ftplugin/_comment/doubleSign.xpt.vim 111: /usr/share/vim/vim80/ftplugin/python.vim 112: ~/.vim/bundle/jedi-vim/after/ftplugin/python/jedi.vim 113: /usr/share/vim/vim80/indent/python.vim 114: /usr/share/vim/vim80/syntax/python.vim 115: ~/.vim/bundle/jedi-vim/after/syntax/python.vim 116: ~/.vim/bundle/vim-airline/autoload/airline/extensions.vim 117: ~/.vim/bundle/vim-airline/autoload/airline/extensions/quickfix.vim 118: ~/.vim/bundle/vim-airline/autoload/airline/extensions/netrw.vim 119: ~/.vim/bundle/vim-airline/autoload/airline/extensions/ctrlp.vim 120: ~/.vim/bundle/vim-airline/autoload/airline/extensions/virtualenv.vim 121: ~/.vim/bundle/vim-airline/autoload/airline/extensions/syntastic.vim 122: ~/.vim/bundle/vim-airline/autoload/airline/extensions/whitespace.vim 123: ~/.vim/bundle/vim-airline/autoload/airline/extensions/po.vim 124: ~/.vim/bundle/vim-airline/autoload/airline/extensions/wordcount.vim 125: ~/.vim/bundle/vim-airline/autoload/airline/extensions/tabline.vim 126: ~/.vim/bundle/vim-airline/autoload/airline/extensions/tabline/autoshow.vim 127: ~/.vim/bundle/vim-airline/autoload/airline/extensions/tabline/tabs.vim 128: ~/.vim/bundle/vim-airline/autoload/airline/extensions/tabline/buffers.vim 129: ~/.vim/bundle/vim-airline/autoload/airline/extensions/tabline/ctrlspace.vim 130: ~/.vim/bundle/vim-airline/autoload/airline/section.vim 131: ~/.vim/bundle/vim-airline/autoload/airline/highlighter.vim 132: ~/.vim/bundle/vim-airline/autoload/airline/themes/dark.vim 133: ~/.vim/bundle/vim-airline/autoload/airline/themes.vim 134: ~/.vim/bundle/vim-airline/autoload/airline/util.vim 135: ~/.vim/bundle/vim-airline/autoload/airline/builder.vim 136: ~/.vim/bundle/vim-airline/autoload/airline/extensions/default.vim 137: ~/.vim/bundle/syntastic/autoload/syntastic/log.vim 138: /usr/share/vim/vim80/syntax/nosyntax.vim 139: ~/.vim/bundle/vim-powerline/autoload/Pl.vim 140: ~/.vim/bundle/vim-powerline/Powerline_default_default_compatible.cache 141: ~/.vim/bundle/vim-powerline/autoload/Pl/Match.vim 142: ~/.vim/bundle/vim-airline/autoload/airline/extensions/tabline/buflist.vim 143: ~/.vim/bundle/vim-airline/autoload/airline/extensions/tabline/formatters/default.vim 144: ~/.vim/bundle/vim-powerline/autoload/Powerline/Functions.vim ```
blueyed commented 7 years ago

Thanks. Being less strict in this regard was suggested for Jedi in https://github.com/davidhalter/jedi/pull/829 - but closed for now. You can use the patch from there though for a more generic solution.

I see that it is more annoying with Vim, where the Python library is more static, whereas Neovim can use python instead.

cmcginty commented 6 years ago

See #685