[vim/vim] Error message printed first time python3 (version 3.7.0) dynamic library is imported (#3117)

566 views
Skip to first unread message

Mario Grgic

unread,
Jun 28, 2018, 9:03:22 AM6/28/18
to vim/vim, Subscribed

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

K.Takata

unread,
Jun 29, 2018, 3:26:32 AM6/29/18
to vim/vim, Subscribed

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.

Ben Jackson

unread,
Jun 30, 2018, 4:22:52 PM6/30/18
to vim/vim, Subscribed

This can trivially be reproduced as follows:

  • build vim against python 3.7
  • run `vim -Nu NONE --cmd 'py3 import sys'"

Ait Brahim Mohammed Khalil

unread,
Jul 1, 2018, 7:04:27 PM7/1/18
to vim/vim, Subscribed

Is there any news on a possible fix ?

Fan Jin

unread,
Jul 2, 2018, 12:19:00 AM7/2/18
to vim/vim, Subscribed

For anyone who's bugged by this, I was able to get around on my Mac with

brew reinstall vim --with-python@2

Ye Zhiling

unread,
Jul 2, 2018, 9:51:56 AM7/2/18
to vim/vim, Subscribed

@bfwg Just FYI, building vim with py2 may cause issues with plugins like python-mode if using some specific settings relying on py3.

Ait Brahim Mohammed Khalil

unread,
Jul 2, 2018, 10:27:37 AM7/2/18
to vim/vim, Subscribed

@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 ?

Oleg Medvedev

unread,
Jul 2, 2018, 10:30:09 AM7/2/18
to vim/vim, Subscribed

@Khalilw1 no, in my case it actually broke the vim-latex-live-preview plugin.

Ye Zhiling

unread,
Jul 2, 2018, 10:31:29 AM7/2/18
to vim/vim, Subscribed

@Khalilw1 YCM works just fine with this error message.

Ait Brahim Mohammed Khalil

unread,
Jul 2, 2018, 10:50:47 AM7/2/18
to vim/vim, Subscribed

@yzlnew thanks for the response although I still find it the warning to be obtrusive 😿. Let us hope a fix is upcoming
@omdv I guess a fix will be needed for it some time soon. thank you for updating me

MoonFruit

unread,
Jul 4, 2018, 10:59:16 PM7/4/18
to vim/vim, Subscribed

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.

Ye Zhiling

unread,
Jul 5, 2018, 2:17:44 AM7/5/18
to vim/vim, Subscribed

@moonfruit :silent! can be used to ignore warnings but I'can figure out which command is causing issues, only the function name.

Chayoung You

unread,
Jul 5, 2018, 2:35:47 AM7/5/18
to vim/vim, Subscribed

@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

Ye Zhiling

unread,
Jul 5, 2018, 2:42:25 AM7/5/18
to vim/vim, Subscribed

@yous It works. Thanks a lot.

Chayoung You

unread,
Jul 5, 2018, 2:49:52 AM7/5/18
to vim/vim, Subscribed

Regardless of installed plugins, silently execute python3 once on the top of your vimrc:

if has('python3')
  silent! python3 1
endif

Ben Mezger (seds)

unread,
Jul 5, 2018, 10:10:05 PM7/5/18
to vim/vim, Subscribed

@yous this worked. But why has it worked?

Chayoung You

unread,
Jul 5, 2018, 10:46:45 PM7/5/18
to vim/vim, Subscribed

@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.

Arseny Nasokin

unread,
Jul 6, 2018, 4:31:32 AM7/6/18
to vim/vim, Subscribed

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

Shoichi Aizawa

unread,
Jul 11, 2018, 1:47:59 AM7/11/18
to vim/vim, Subscribed

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?

Andreas Wachowski

unread,
Jul 11, 2018, 3:13:34 AM7/11/18
to vim/vim, Subscribed

@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

Shoichi Aizawa

unread,
Jul 11, 2018, 4:00:48 AM7/11/18
to vim/vim, Subscribed

@andreaswachowski

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... 😢

Ben Jackson

unread,
Jul 11, 2018, 4:03:46 AM7/11/18
to vim/vim, Subscribed

If you are having trouble with YCM please see the first section of the Readme.

Seth Deckard

unread,
Jul 11, 2018, 9:55:52 AM7/11/18
to vim/vim, Subscribed

@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.

Shoichi Aizawa

unread,
Jul 11, 2018, 10:47:53 AM7/11/18
to vim/vim, Subscribed

@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 🙏

James Lance

unread,
Jul 16, 2018, 5:12:47 PM7/16/18
to vim/vim, Subscribed

@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.

Ait Brahim Mohammed Khalil

unread,
Jul 16, 2018, 7:40:28 PM7/16/18
to vim/vim, Subscribed

@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.

Chayoung You

unread,
Jul 22, 2018, 5:37:57 AM7/22/18
to vim/vim, Subscribed

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

K.Takata

unread,
Jul 22, 2018, 9:57:09 AM7/22/18
to vim/vim, Subscribed

Closed #3117.

K.Takata

unread,
Jul 22, 2018, 9:57:09 AM7/22/18
to vim/vim, Subscribed

Fixed by 8.1.0201, so closing.

@yous You can just use has('patch-8.1.201').

Reply all
Reply to author
Forward
0 new messages