lumbric
lumbric

Reputation: 9053

Running VIM from a Python virtulenv using Python plugins

When I start VIM after activating an Python virtulenv, Python plugins can't find their modules, because they are installed in the system, not in the project's virtualenv.

I am using the aw-watcher-vim plugin, which uses a Python library.

When I create a virtualenv and activate it:

virtualenv -p python3 my_env
. my_env/bin/activate

VIM can't find the module at /usr/local/lib/python3.6/dist-packages/aw_core/ anylonger and prints the following errors:

['Traceback (most recent call last):',
'  File "~/.dot-file-repo/neovim/plugged/aw-watcher-vim/plugin/vimwatcher.py", line 6 , in <module>',
'    from aw_core.log import setup_logging',
'ModuleNotFoundError: No module named ''aw_core''',
''] 

(Slightly reformated for readablity.)

It would be nice to use autocompletion using the code from the virtualenv (via Jedi or so), but let the other plugins find their Python modules. Is there a good solution to this use case?

Upvotes: 0

Views: 812

Answers (1)

Artem Trunov
Artem Trunov

Reputation: 1415

While some comments suggest to import globally instaled pacckages to virtualenv, I'd suggest to set options in /vimrc to use the system python:

set pythondll=/usr/bin/python
set pythonthreedll=/usr/bin/python3

or whatever your system python is.

The advantage is that you virtual envs are untouched and are used according to your needs.

Upvotes: 1

Related Questions