Youcompleteme: The imp module is deprecated in favour of importlib

Created on 30 Jun 2018  Â·  15Comments  Â·  Source: ycm-core/YouCompleteMe

I have deprecation warning at VIM startup:
"DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses"

macOS: 10.13.5
VIM: 8.1 (installed via brew)
Python: 3.7.0 (installed via brew)
Latest version of YouCompleteMe plugin (installed via VimPlug)

How I can fix that?

Most helpful comment

Sure but putting ‘silent! py3 pass’ in your vimrc is a better workaround.

All 15 comments

I'm also getting the same warning:

Error detected while processing function youcompleteme#Enable[3]..<SNR>80_SetUpPython:
line   42:
/must>not&exist/foo:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses

macOS: 10.13.5
VIM: 8.1 (brew install macvim --with-override-system-vim)
Python: 2.7.15 (brew)
Also on the latest version of YouCompleteMe (./install.py --go-completer --js-completer and using vim-plug).

I've tried uninstall/re-installing vim and re-installing YCM to no avail.

Update: looks like the new version of vim was installing with python3 somehow (via :version), was able to fix my issue by installing with brew install macvim --with-override-system-vim --with-python@2.

Still, you shouldn't be getting errors when using python 3 vim or runtime. I will try upgrading macvim and see what happens

This is not a YCM issue.

I can reproduce with a completely different plugin using the following vimrc:

set rtp+=$HOME/.vim/bundle/vim-rtags
filetype plugin indent on

This should be reported upstream to either vim or macvim.

The issue appears to be that python 3.7 is now issuing a deprecation warning for import that is done by vim's if_python3.c.

It can be reproduced with vim -Nu NONE --cmd 'py3 import sys'

BenMBP:vim ben$ tvim -Nu NONE --cmd 'py3 import sys'
Error detected while processing pre-vimrc command line:
/must>not&exist/foo:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
Press ENTER or type command to continue
BenMBP:vim ben$

may be it is time for youcompleteme to use python3 as default interpreter. since ubuntu18.04 use python3 as default python.

That's completely irrelevant? This only happens (completely independently of YCM) if you compile Vim with Python 3, so I don't see what we could possibly change that would affect that.

strictly, python 3.7 where the module (used by Vim internals) is deprecated.

Way to suppress warning on Mac OSX

vim ~/.vim/bundle/YouCompleteMe/autoload/youcompleteme.vim

search for

exec s:python_until_eof

just before

from __future__ import unicode_literals

mentioned below prepend silent! before exec s:python_until_eof

 silent! exec s:python_until_eof
 from __future__ import unicode_literals
 from __future__ import print_function
 from __future__ import division

That is not a solution.

@puremourning edited my comment

Sure but putting ‘silent! py3 pass’ in your vimrc is a better workaround.

@puremourning did brew upgrade after which I removed that 'silent! ' from the file. And now it is working file. I hope things are sorted in other's vim also

Vim was fixed a while ago.

Was this page helpful?
0 / 5 - 0 ratings