I have compiled vim with --enable-pythoninterp --enable-python3interp and when I execute :python3 1 from vim I get:
/must>not&exist/foo:1: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
message on first run only.
I am on macOS 10.13.5, Xcode 9.3 and Python 3.7.0.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
Oh, imp is deprecated since Python 3.4.
https://docs.python.org/3.7/library/imp.html#module-imp
It seems that we need to use importlib instead.
This can trivially be reproduced as follows:
Is there any news on a possible fix ?
For anyone who's bugged by this, I was able to get around on my Mac with
brew reinstall vim --with-python@2
@bfwg Just FYI, building vim with py2 may cause issues with plugins like python-mode if using some specific settings relying on py3.
@yzlnew I think YouCompleteMe would also complain. If I understand the issue correctly this is just a warning from vim on usage of imp. Meaning that at this point nothing should break am I right ?
@Khalilw1 no, in my case it actually broke the vim-latex-live-preview plugin.
@Khalilw1 YCM works just fine with this error message.
I think maybe we can simply add vim specific warning filters to ignore this warning.
reference: python doc for warnings.
And later replace imp with importlib for python 3.1 or above.
@moonfruit :silent! can be used to ignore warnings but I'can figure out which command is causing issues, only the function name.
@yzlnew If you're getting warnings because of YCM, try edit autoload/youcompleteme.vim:
diff --git a/autoload/youcompleteme.vim b/autoload/youcompleteme.vim index 597eb020..32461fa9 100644 --- a/autoload/youcompleteme.vim +++ b/autoload/youcompleteme.vim @@ -180,7 +180,7 @@ endfunction function! s:SetUpPython() abort - 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
@yous It works. Thanks a lot.
Regardless of installed plugins, silently execute python3 once on the top of your vimrc:
if has('python3') silent! python3 1 endif
@yous this worked. But why has it worked?
@benmezger When we execute :python3 on Vim, DoPyCommand() is invoked which calls Python3_Init(). Python3_Init() calls PyImport_AppendInittab("vim", Py3Init_vim);, and Py3Init_vim calls populate_module(vim_module), and that's where actually Vim imports imp module.
We forced to skip warnings and errors from :python3 1 and DeprecationWarning is printed only once, so the error message is gone.
I analysed the code and we don't need the imp.find_module executed beforehand. For load_module we can use instead importlib.import_module() without any loss of functionality
Regardless of installed plugins, silently execute python3 once on the top of your > vimrc:
if has('python3') silent! python3 1 endif
Adding this above at the top of my vimrc file managed to eliminate the DeprecationWarning: the imp module... message but I have another problem and get kicked out of Vim because of that; please see the following error:
Vim: Caught deadly signal SEGV
Vim: Finished.
Segmentation fault: 11
This seems to occur only when YouCompleteMe is enabled. And this started happenning since around Python 3.7.0 was released.
Any YMC user has encountered this problem?
@shoichiaizawa I guess you will simply have to recompile YouCompleteMe after changing the Python distribution. Change to YouCompleteMe's installation directory and execute ./install.py, then try again starting vim. For details, see https://github.com/Valloric/YouCompleteMe#installation
Thanks for the message. I tried reinstalling YCM but it didn't help me. Just in case, I also did brew reinstall Vim and Python 3 but they didn't resolve the issue either... 😢
If you are having trouble with YCM please see the first section of the Readme.
@shoichiaizawa Your problem is completely unrelated to this issue but in short you need to make sure that you run ./install.py with the exact same python that vim is compiled with, not just the same version but the exact same installation (in the case you're using pyenv, etc.). You mention you're using homebrew which means vim will likely be compiled with homebrew installed python, try running /usr/local/bin/python3 ./install.py.
@andreaswachowski @puremourning @sethdeckard
I recompiled YCM with the Homebrew version of Python 3 and now works fine like before. The problem was persistent with the pyenv version of Python 3 (even though the pyenv Python 3 was installed with the --enable-framework option and Vim was working fine with it up until recently). I initially thought my problem was related to this issue to some extent as the problem started happening since when Python 3.7.0 was released.
Thanks for leaving the comments anyway, even though it was off topic 🙏
@shoichiaizawa Can you explain what you did a little more? I tried recompiling with the homebrew python3, but I'm still seeing this error.
I tried the trick of firing off python3 at the top of my vimrc, but that feels like I'm just hiding the problem, not actually fixing it.
@neybar here is my current understanding of it hope this helps, I guess because of the deprecation a warning is raised since vim still uses imp module the only way to fix is to adhere to the new way which is importlib. There is a PR I saw which fixes the problem I guess it is not yet merged. I think compiling with homebrow python3 won't fix the problem because the problem is because of python 3.7.
Patch 8.1.0201 has introduced which fixes this issue. 79a494d
Homebrew vim has also updated to 8.1.0202, so the previous fix can be updated to:
if has('python3') && !(v:version >= 802 || v:version == 801 && has('patch201')) silent! python3 1 endif
Closed #3117.