Skip to content

Autocompletion for virtual environment modules working in Python 2 but not in Python 3 #503

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

Closed
anderslundstedt opened this issue Nov 24, 2015 · 8 comments

Comments

@anderslundstedt
Copy link

With vim compiled with +python -python3 and with a Python 2 virtual environment activated, completion works for everything.

With vim compiled with -python +python3 and with a Python 3.5 virtual environment (created with the pyvenv tool) completion works for everything except for modules installed in the virtual environment.

@tony
Copy link

tony commented Dec 21, 2015

There is no way to do Python 3 + Virtualenv on vim as of December 20, 2015.

I was going to do a project in pure Python 3.5, however came to a surprise when other packages relied upon for handling virtualenv didn't work with python 3.x virtualenvs. To see why, see the tickets linked to below.

With vim compiled with -python +python3 and with a Python 3.5 virtual environment (created with the pyvenv tool) completion works for everything except for modules installed in the virtual environment.

Are you sure the virtualenv is really activated in python 3? Do you use a separate plugin for your virtualenv?

With -python +python3, what you're experiencing may be because virtualenv isn't activating and you're only getting completion for the standard lib packages.

On neovim, it's possible to simulate +python and +python3 simultaneously. I've had working jedi completion, but like you, only for standard library packages.

Related issues, #467, jmcantrell/vim-virtualenv#45, python-mode/python-mode#406

Related reddit thread: https://www.reddit.com/r/vim/comments/2j0fxc/python_3_completion_vim_plugins/

@mikepqr
Copy link

mikepqr commented May 19, 2016

Any news on this? Looks like there's been some movement on some of the issues @tony referenced since his previous comment. Would be great to get jedi-vim working with python3!

@blueyed
Copy link
Collaborator

blueyed commented May 20, 2016

It certainly is possible, and you might only be missing the virtualenv activation.
Apart from that, Neovim is more flexible and you can use 2 + 3 at the same time.
I also recoomend pyenv + pyenv-virtualenv.

@mikepqr
Copy link

mikepqr commented May 20, 2016

neovim (and pip install neovim in the relevant virtualenv) worked for me. Thanks!

Could you say more about how to make it work in vanilla vim? Do I need to do something more than activate the virtualenv in the shell from which I run vim file.py?

I agree pyenv and pyenv-virtualenv are great, but I don't see how they are relevant to this problem. Am I missing something?

@davidhalter
Copy link
Owner

Virtualenv support is still broken in Jedi. I plan to tackle it soon. (This issue: davidhalter/jedi#385). Because until Jedi really supports it, it's just not a clean solution.

@mikepqr
Copy link

mikepqr commented Jun 12, 2016

Thanks. In this meantime, for anyone reading this: I got things working for python3 virtual environments using the following ugly hack, which I added to the end of my ~/.vimrc.

" Add the virtualenv's site-packages to vim path
py3 << EOF
import os.path
import sys
if 'VIRTUAL_ENV' in os.environ:
    project_base_dir = os.environ['VIRTUAL_ENV']
    sys.path.insert(0, project_base_dir)
EOF

This works in the sense that the sys.path used by jedi-vim includes the active virtualenv's site-packages, and expansion, documentation, goto defintion etc. all work. But seems particularly ugly. It only works for python3. I have to activate the appropriate virtual environment before launching vim. I need to know what I'm working on before I open vim, and I can only work on one virtualenv per vim session. But it does work.

@blueyed
Copy link
Collaborator

blueyed commented Jun 12, 2016

@davidhalter
Copy link
Owner

Will be fixed with davidhalter/jedi#385

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants