Closed meunierd closed 11 years ago
second this
I use YCM and VIM on top of a virtualenv instance, what's the matter? I found no issue...
No virtualenv specific packages are suggested. On 2013-06-19 10:02 PM, "Francisco Lopes" notifications@github.com wrote:
I use YCM and VIM on top of a virtualenv instance, what's the matter? I found no issue...
— Reply to this email directly or view it on GitHubhttps://github.com/Valloric/YouCompleteMe/issues/380#issuecomment-19726798 .
Virtualenvs is working for me as well.
Might want to check out python-mode, or more specifically its virtualenv module. Jedi-vim is probably implementing something similar.
Following the advice from your comment, I was able to get virtualenv support working by copying out this section from the virtualenv module into my vimrc:
python << EOF
import sys, vim, os
ve_dir = vim.eval('$VIRTUAL_ENV')
ve_dir in sys.path or sys.path.insert(0, ve_dir)
activate_this = os.path.join(os.path.join(ve_dir, 'bin'), 'activate_this.py')
# Fix for windows
if not os.path.exists(activate_this):
activate_this = os.path.join(os.path.join(ve_dir, 'Scripts'), 'activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
EOF
Although I'd certainly prefer it if this were integrated into the plugin itself.
There is also https://github.com/jmcantrell/vim-virtualenv, which provides virtualenv functionality like python-mode, but also allows additional functionality
This sounds like a Jedi issue (which YCM uses). I suggest you file the issue report upstream.
I had likely the same issue: Unable to jump to a declaration in a namespace package within the virtual environment.
I deinstalled YouCompleteMe and installed jedi-vim and now it is working as expected. So I would suppose an issue with YouCompleteMe (may be not properly using jedi). Since jedi-vim is the reference implementation for jedi and it is just working, saying there is a problem with jedi seems incomprehensible to me.
This issue should be reopened: vim + YCM will use a virtualenv if launched from within that virtualenv, but will not adjust if the environment is updated in some way (for example: via vim-virtualenv, mentioned above). jedi-vim on the other hand will update accordingly.
This particularly matters if the user is using a persistent graphical vim, as opposed to short lived terminal sessions, as there's no quick way to toggle virtualenvs. It's definitely not an issue with jedi itself - as diefans mentions, that would mean jedi-vim would have similar issues.
@Valloric Please re-open as per the previous comment.
I could imagine that the problem is with ycmd not adjusting to an activated virtualenv after Vim has been started. I have tried :YcmRestartServer
, but that did not help either.
I have activated the virtualenv using vim-virtualenv in a gvim instance.
I can confirm what @chrischambers says: If I activate a virtualenv in a terminal and run vim in a terminal, then I do get YCM/Jedi autocompletion for, for example, things inside a third-party package that is installed in the virtualenv. But if I open gvim then activate a virtualenv in gvim using python-mode's :PyModeVirtualenv
command this completion doesn't work.
Just discovered that if I activate the virtualenv in gvim using this plugin https://github.com/jmcantrell/vim-virtualenv and then do :YcmRestartServer
then the completion works. Does not work with the Pymode plugin's virtualenv activation.
If you are using vim-virtualenv, I define a custom command in vimrc to restart YcmServer everytime I change virtualenv from inside vim. You can now use :Venv command with tab completion for virtualenvs.
"" function to list virtualenvs
:fun ReturnVirtualEnvs(A,L,P)
: return system("ls -d /Users/dhruv/Envs/*/ \| cut -d'/' -f5") ""change the directory path to point to your virtualenvs
:endfun
"" changing virtualenv should restart ycmserver
:command -nargs=+ -complete=custom,ReturnVirtualEnvs Venv :VirtualEnvActivate <args> | YcmRestartServer
Now that YCM supports python 3, what is the status of virtualenv support? Specifically, if you compiled with python 3 and are in a python 2 venv.
The fact that you compiled YCM against python3 is irrelevant for the Python completion, because we use a wrapper of jedi JediHTTP which we spawn using the python interpreter used by the ycmd
server which is the python used when you compile YCM or it uses the python specified by then g:ycm_python_binary_path
option. Look the docs for more info, like: https://github.com/Valloric/YouCompleteMe#python-semantic-completion
When I compile YCM with python3, I don't get completion for packages installed in py2 virtualenvs. Is this a bug, or is there something wrong with my configuration?
@jck set the g:ycm_python_binary_path
to the path of the python binary inside the virtualenv,
YCM fails with the import error since it was compiled with Python 3.
@jck use this option https://github.com/Valloric/YouCompleteMe#the-gycm_path_to_python_interpreter-option to point to the Python you've used to compile YCM and g:ycm_python_binary_path
to point to the virtualenv Python binary
That seems to work. Thanks!
@vheon let g:ycm_python_binary_path = 'python'
works well, thx
Using jedi-vim virtualenv support works as expected, but doesn't appear to be enabled with YCM.