vim and powerline

January 24, 2020 @ 11:51

Do you use Vim and Powerline? If so, you may have got this error message at some point, when using a Virtualenv:

Traceback (most recent call last):
  File "<string>", line 4, in <module>
ModuleNotFoundError: No module named 'powerline'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<string>", line 9, in <module>
ModuleNotFoundError: No module named 'powerline'
An error occurred while importing powerline module.
This could be caused by invalid sys.path setting,
or by an incompatible Python version (powerline requires
Python 2.6, 2.7 or 3.2 and later to work). Please consult
the troubleshooting section in the documentation for
possible solutions.
Unable to import powerline, is it installed?

I know how to solve this! Put this in your .vimrc:

" workaround issue with powerline + virtualenv
" https://github.com/powerline/powerline/issues/1908
python3 << EOF
import sys
path = "/usr/lib/python{}.{}/site-packages/".format(
    sys.version_info.major, sys.version_info.minor)
sys.path.append(path)
EOF