ycm-core / YouCompleteMe

A code-completion engine for Vim
http://ycm-core.github.io/YouCompleteMe/
GNU General Public License v3.0
25.44k stars 2.81k forks source link

'g:ycm_python_sys_path' seems not working #3195

Closed cgjosephlee closed 5 years ago

cgjosephlee commented 5 years ago

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside the brackets) before filing your issue:

Thank you for adhering to this process! It ensures your issue is resolved quickly and that neither your nor our time is needlessly wasted.

Issue Details

I'm heavily rely on anaconda to code python in v3.6, and I installed python and a batch of packages via miniconda. I want to get autocompletions for packages installed by miniconda, so I tried following workarounds.

  1. configure g:ycm_python_sys_path and g:ycm_python_interpreter_path in .vimrc

NOT work

let g:ycm_python_interpreter_path = '/usr/local/miniconda3/bin/python'
let g:ycm_python_sys_path = ['/usr/local/miniconda3/lib/python3.6']
  1. configure sys_path and interpreter_path in .ycm_extra_conf.py and load

work But this is not a solution for global environment.

def Settings( **kwargs ):
  return {
    'interpreter_path': '/usr/local/miniconda3/bin/python'
    'sys_path': [
      '/usr/local/miniconda3/lib/python3.6',
    ]
  }
  1. configure g:ycm_python_sys_path, g:ycm_python_interpreter_path, g:ycm_extra_conf_vim_data and g:ycm_global_ycm_extra_conf in .vimrc and link to ~/.ycm_global_extra_conf.py

work .vimrc

let g:ycm_python_interpreter_path = '/usr/local/miniconda3/bin/python'
let g:ycm_python_sys_path = ['/usr/local/miniconda3/lib/python3.6']
let g:ycm_extra_conf_vim_data = [
 \'g:ycm_python_interpreter_path',
 \'g:ycm_python_sys_path']
let g:ycm_global_ycm_extra_conf = '~/.ycm_global_extra_conf.py'

~/.ycm_global_extra_conf.py

def Settings(**kwargs):
    client_data = kwargs['client_data']
    return {
        'interpreter_path': client_data['g:ycm_python_interpreter_path'],
        'sys_path': client_data['g:ycm_python_sys_path']
    }

Trial an error turned out to these results although I did not quite understand the differences.

Diagnostic data

Output of vim --version

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Nov 29 2017 18:37:46)
Included patches: 1-503, 505-680, 682-1283
Compiled by root@apple.com
Normal 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/dyn      +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      -lua             -rightleft       +windows
+diff            +menu            +ruby/dyn        +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/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -DMACOS_X_UNIX  -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L/usr/local/lib -o vim        -lm -lncurses  -liconv -framework Cocoa

Output of YcmDebugInfo

Printing YouCompleteMe debug information...
-- Client logfile: /var/folders/vb/h0jz0xxj5gsgq639hq5l4ft80000gn/T/ycm_tbz7Ok.log
-- Server Python interpreter: /usr/bin/python
-- Server Python version: 2.7.10
-- Server has Clang support compiled in: False
-- Clang version: None
-- Extra configuration file found and loaded
-- Extra configuration path: /Users/josephlee/.ycm_global_extra_conf.py
-- Python completer debug information:
--   Python interpreter: /usr/local/miniconda3/bin/python
--   Python path: [u'/usr/local/miniconda3/lib/python3.6', u'/usr/local/miniconda3/lib/python36.zip', u'/usr/local/miniconda3/lib/python3.6', u'/usr/local/miniconda3/lib/python3.6/lib-dynload', u'/usr/local/miniconda3/lib/python3.6/site-packages', u'/usr/local/miniconda3/
lib/python3.6/site-packages/bcbio_gff-0.6.4-py3.6.egg']
--   Python version: 3.6.4
--   Jedi version: 0.13.1
--   Parso version: 0.3.1
-- Server running at: http://127.0.0.1:57756
-- Server process ID: 17556
-- Server logfiles:
--   /var/folders/vb/h0jz0xxj5gsgq639hq5l4ft80000gn/T/ycmd_57756_stdout_PIH4cw.log
--   /var/folders/vb/h0jz0xxj5gsgq639hq5l4ft80000gn/T/ycmd_57756_stderr_1vRrSy.log

Contents of YCM, ycmd and completion engine logfiles

OS version, distribution, etc.

macOS 10.13.6

Output of build/install commands

YCM was built successfully with mac builtin python 2.7.10 /usr/bin/python.

micbou commented 5 years ago

configure g:ycm_python_sys_path and g:ycm_python_interpreter_path in .vimrc NOT work

It doesn't work because these options are not defined by YCM. They are just an example of how you can set sys.path and the Python interpreter path through Vim options with a global extra conf. You could name them to something completely different like g:my_sys_path and g:my_interpreter_path.

work But this is not a solution for global environment.

It is. You just need to use a global extra conf. See the g:ycm_global_ycm_extra_conf option.

If you have more questions, please ask them on the Gitter room or the ycm-users Google group.