-
-
Notifications
You must be signed in to change notification settings - Fork 372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
jedi-vim does not actually use virtualenv #685
Comments
Jedi's support for virtualenvs is currently very marginal. IMO we still have to wait for davidhalter/jedi#385. Sorry, but I really don't like venv support either. However it will get better and I'm finally starting to have time for it. |
I'm experiencing this identical issue. Hopefully it gets fixed soon. Assuming no one's actively working on this, and without more information, I assume the problem involves the search path for the virtual environment's site-packages within Jedi; the logic used for jedi.evaluate.sys_path.get_venv_path causes a ton of side effects that are hard for me to trace. Is this part of the code undergoing major refactoring in davidhalter/jedi#385 , or is this something that would be worth my time to wrap my head around and address in Jedi's code base to fix this issue? Eg, if I dedicate a ton of time for this and come up with a good solution, will the pull request be accepted or is it likely to conflict with the new architectural direction proposed in davidhalter/jedi#385? |
You might want to try davidhalter/jedi#829 in the meantime. |
@blueyed wow, thanks a bunch! This completely fixes the problem. I'm curious why this might cause segfaults... @davidhalter Definitely worth another look at davidhalter/jedi#829 . Optional activation would be most excellent (like a "use virtualenv in unsafe, but usable mode"). Thanks again @blueyed |
@pappasam The Python API changes. So different Python versions have different C APIs. This leads to segfaults. Virtualenv support is the next thing on my list (after the parser release in summer). |
@skamsie @blueyed I found a simple workaround, assuming you use Python 3.5 or 2.7 on Linux Mint (can't vouch for any other environment at this point): " in your plugin list (assuming you use vim-plug):
Plug 'jmcantrell/vim-virtualenv'
" in your plugin constants configuration section
let g:virtualenv_auto_activate = 1 I confirm that 3.6 does not work yet; David Halter has already confirmed Python 3.6 development is pending other changes to core Jedi. Hope this helps! |
I've actually added this function in my function vim {
PYTHONPATH=`python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"` /usr/bin/vim "$@"
} modules installed in current virtualenv library have priority over the one vim is compiled with. By the way, if vim is compiled with python 2.x and current virtualenv use python 3.x, any module from The Python Standard Library -like |
@WnP I wouldn't recommend this. You're screwing up everything by setting the PYTHONPATH. |
@davidhalter everything like… what? On my setup PYTHONPATH is not set at all by default |
Well it's dangerous for the above reasons. Things might segfault with this. I'm just not recommending it to viewers of this thread. |
@davidhalter ok, I see, thanks for the advice and all your work on vim-jedi |
This script in .vimrc works for me:
|
@cmcginty I strongly discourage people from doing that. I know it works, but it can lead to segmentation faults and a lot of other issues. Proper virtualenv support is coming, if you want to try it, it's part of jedi's master branch and especially venvs created with |
@davidhalter |
Well, I currently run jedi-vim master with latest jedi and it works pretty well. Eventually we want to adjust some things in jedi-vim to handle virtualenvs better. This is something we don't have to do, but it's just really easy. Scan for virtualenvs/Python environments every now and then and let the user choose which one he wants to use. |
Sounds good. Does Jedi has an API to return the known (virtual)envs? |
ATM I use neovim with neovim (pep8 and yapf) python package(s) installed inside given virtual env. With this configuration if I source my venv before opening neovim completion and doc are available from given virtual env. I also use deoplete for completion and ale for syntax checking (both are async). This setup is (at least for me) the perfect setup for python development using [neo]vim. Check my .vimrc for configuration details Let me know your through. |
Activate virtualenv before opening neovim works. |
@xarthurx I use a simple hack to be able to get completions when changing the virtualenv inside vim. I do this by changing the |
If you change the virtualenv from within vim using |
When jedi-vim doesn't use a venv, it's probably because $VIRTUALENV is not set. What we should improve is selection of venvs, because for Jedi it's not a problem anyway. Jedi can deal with venvs very easily. So it's basically writing a good VIM UI for it. I would not recommend using hacks like |
For reference: #836 |
Virtualenvs are now supported very well. If you don't like the current support, we can discuss it. However I'm pretty sure there's not a lot that can be improved (there's also no open bugs in Jedi). |
Thanks for pointing to that. As a note for posterity, it seems there was a typo and the environment variable is actually called |
Issue
It states in the documentation that it "Supports virtualenv", but It does not work for me.
Steps to reproduce
I have a project directory and inside I have a venv folder that was created with:
virtualenv -p /usr/local/bin/python3 venv
I source this venv with the usual command:
source venv/bin/activate
I install some packages in this venv: hamcrest and requests
I start vim in this directory
result of
:! python --version
is Python 3.4.1I go to a file in my project that uses either hamcrest or requests, I do <leader>d, it works, but when I check the path of the file it went to is actually
on/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/hamcrest/__init__.py
I uninstall hamcrest from my system python 2.7.13
I start vim again and go to that file, do <leader>d:
"jedi-vim: Couldn't find any definitions for this."
My conclusion is that in reality jedi-vim does not actually use the virtual env...
Versions
The text was updated successfully, but these errors were encountered: