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

python interpreter is not searched in the PATH #2641

Closed ghost closed 7 years ago

ghost commented 7 years ago

Issue Details

I have a python virtualenv enabled. I start vim and try to get semantic completions on modules in the virtualenv and/or the modules installed in it.

Completion should be working, the python interpreter used should be the one of the virtualenv

I noticed that the Jedi server always uses the python version stored in third_party/ycmd/PYTHON_USED_DURING_BUILDING instead of the configured one (the results are coming from a python3 virtualenv)

If I change the python version in the PYTHON_USED_DURING_BUILDING file it is the one used, but the server won't run if it's a different version.

Setting the path to 'python' I would expect it will run with the first python from PATH (the virtualenv one is the first one, as it should be)

Diagnostic data

Output of vim --version

vim.version.txt

Output of YcmDebugInfo

YcmDebugInfo output
Printing YouCompleteMe debug information...                                                              
-- Client logfile: /tmp/ycm_tuw14sm8.log                                                                 
-- Server Python interpreter: /usr/bin/python                                                            
-- Server Python version: 2.7.13                                                                         
-- Server has Clang support compiled in: True                                                            
-- Clang version: clang version 4.0.0 (tags/RELEASE_400/final)                                           
-- No extra configuration file found                                                                     
-- Server running at: http://127.0.0.1:47169                                                             
-- Server process ID: 20329                                                                              
-- Server logfiles:                                                                                      
--   /tmp/ycmd_47169_stdout_1wj8wejc.log                                                                 
--   /tmp/ycmd_47169_stderr_w_7tdzuw.log

Contents of YCM, ycmd and completion engine logfiles

ycmd_47169_stdout_1wj8wejc.log.txt ycmd_47169_stderr_w_7tdzuw.log.txt the ycmd log is an empty file

OS version, distribution, etc.

OS: Debian Stretch

vimrc has

let g:ycm_python_binary_path = 'python'
vheon commented 7 years ago

Here you will find the answer https://github.com/Valloric/YouCompleteMe#python-semantic-completion

vheon commented 7 years ago

Ops I didn't read the last line, sorry :/

vheon commented 7 years ago

So the only thing that remains is if you started vim from the directory of the project

vheon commented 7 years ago

Also can you post the YcmDebugInfo after opening a python file? I'm not seeing the JediHTTP info in there right now.

ghost commented 7 years ago

I found the problem while testing the same setup on another computer. Starting Vim on the second one I got a message about setting g:ycm_server_python_interpreter to the interpreter for the server.

let g:ycm_python_binary_path = 'python'
let g:ycm_server_python_interpreter = '/usr/bin/python2'

Adding that line solved my issue.

by the way, the output with a python file open was

-- Client logfile: /tmp/ycm_280xmlw_.log
-- Server Python interpreter: /usr/bin/python
-- Server Python version: 2.7.13
-- Server has Clang support compiled in: True
-- Clang version: clang version 4.0.0 (tags/RELEASE_400/final)
-- No extra configuration file found
-- Python completer debug information:
--   JediHTTP running at: http://127.0.0.1:44877
--   JediHTTP process ID: 25137
--   JediHTTP executable: /home/-----/.vim/bundle/YouCompleteMe/third_party/ycmd/third_party/JediHTTP/jedihttp.py
--   JediHTTP logfiles:
--     /tmp/jedihttp_44877_stdout_hoY1Ku.log
--     /tmp/jedihttp_44877_stderr_w0QTlG.log
--   Python interpreter: /usr/bin/python
-- Server running at: http://127.0.0.1:41817
-- Server process ID: 25096
-- Server logfiles:
--   /tmp/ycmd_41817_stdout_42w1smas.log
--   /tmp/ycmd_41817_stderr_dfvufymf.log 

Now it uses the right python executable

Hnasar commented 6 years ago

I'm not sure why let g:ycm_python_binary_path = 'python' isn't the default. I experienced the same issue: completion would only work in python2 if I ran install.py with my python2 virtualenv, and it would only work in python3 if I built it with my python3 virtualenv.

By setting the python_binary_path then it works for me automatically no matter which virtualenv/python version I'm using.