简体   繁体   中英

Vim syntastic shows import error for Python VirtualEnv libraries

I have scrooloose/syntastic Plugin install on my vim. And I have installed pylint library globally.

sudo python -m pip install pylint

However for my project I have VirtualEnv and all the necessary libraries for that project is installed in VirtualEnv.

The problem is,

  • Syntastic shows import error for libraries which are part of virtualenv
  • My Jedi-vim plugin shows me all the suggestion and I am able to run the problem so there is nothing wrong from python side.

You have to install pylint inside your virtualenv to be recognized by syntastic. The easiest way is to run

(virtualenv) $ pip install pylint

inside your virtualenv.

If you have too many projects and want to avoid running that command to install pylint to each project you can make vim run it for you. Add the following to your .vimrc:

py3 << EOF
import os
if 'VIRTUAL_ENV' in os.environ:
  os.system('pip install pylint')
EOF

This will not avoid using the virtualenv pylint, as this will install pylint to each virtualenv that you open with vim. I believe it is possible to change the pylint path using g:syntastic_python_pylint_exe but as you can see here , it is not recommended (pylint is dependent on the python version and it would be easy to mess up the versions I guess). Notice that this approach adds some delay when opening the file, but if you don't mind wait 1 second more to open your file, this approach is interesting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM