YouCompleteMe unavailable:cannot import name _remove_dead_weakref

Created on 25 Jan 2018  ·  43Comments  ·  Source: ycm-core/YouCompleteMe

Issue Prelude

Please complete these steps and check these boxes (by putting an x inside
the brackets) _before_ filing your issue:

  • [x] I have read and understood YCM's CONTRIBUTING document.
  • [x] I have read and understood YCM's CODE_OF_CONDUCT document.
  • [x] I have read and understood YCM's README, especially the
    Frequently Asked Questions section.
  • [x] I have searched YCM's issue tracker to find issues similar to the one I'm
    about to report and couldn't find an answer to my problem. (Example Google
    search.
    )
  • [x] If filing a bug report, I have included the output of vim --version.
  • [x] If filing a bug report, I have included the output of :YcmDebugInfo.
  • [x] If filing a bug report, I have attached the contents of the logfiles using
    the :YcmToggleLogs command.
  • [x] If filing a bug report, I have included which OS (including specific OS
    version) I am using.
  • [x] If filing a bug report, I have included a minimal test case that reproduces
    my issue, including what I expected to happen and what actually happened.
  • [x] If filing a installation failure report, I have included the entire output
    of install.py (or cmake/make/ninja) including its invocation
  • [x] I understand this is an open-source project staffed by volunteers and
    that any help I receive is a selfless, heartfelt _gift_ of their free time. I
    know I am not entitled to anything and will be polite and courteous.
  • [x] I understand my issue may be closed if it becomes obvious I didn't
    actually perform all of these steps.

Thank you for adhering to this process! It ensures your issue is resolved
quickly and that neither your nor our time is needlessly wasted.

Issue Details

I received this message in the bottom when I opened the VIM.
questions: YouCompleteMe unavailable:cannot import name _remove_dead_weakref

  • What did you do?

Include steps to reproduce here.

Include description of a minimal test case, including any actual code required
to reproduce the issue.

  • What did you expect to happen?

Include description of the expected behaviour.

  • What actually happened?

Include description of the observed behaviour, including actual output,
screenshots, etc.

Diagnostic data

Output of vim --version

vim --version VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jan 25 2018 17:23:52)

Output of YcmDebugInfo

E492: Not an editor's command

Contents of YCM, ycmd and completion engine logfiles

Include link here to a gist containing the entire logfiles for ycm, ycmd
and any completer logfiles listed by :YcmToggleLogs.

OS version, distribution, etc.

ubuntu 16.04

Output of build/install commands

install.py

  • vim --version VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jan 25 2018 17:23:52)
    +acl +farsi +mouse_sgr -tag_any_white
    +arabic +file_in_path -mouse_sysmouse -tcl
    +autocmd +find_in_path +mouse_urxvt +termguicolors
    -autoservername +float +mouse_xterm +terminal
    +balloon_eval +folding +multi_byte +terminfo
    +balloon_eval_term -footer +multi_lang +termresponse
    +browse +fork() -mzscheme +textobjects
    ++builtin_terms +gettext -netbeans_intg +timers
    +byte_offset -hangul_input +num64 +title
    +channel +iconv +packages +toolbar
    +cindent +insert_expand +path_extra +user_commands
    +clientserver +job +perl/dyn +vertsplit
    +clipboard +jumplist +persistent_undo +virtualedit
    +cmdline_compl +keymap +postscript +visual
    +cmdline_hist +lambda +printer +visualextra
    +cmdline_info +langmap +profile +viminfo
    +comments +libcall +python/dyn +vreplace
    +conceal +linebreak +python3/dyn +wildignore
    +cryptv +lispindent +quickfix +wildmenu
    +cscope +listcmds +reltime +windows
    +cursorbind +localmap +rightleft +writebackup
    +cursorshape +lua +ruby/dyn +X11
    +dialog_con_gui +menu +scrollbind -xfontset
    +diff +mksession +signs +xim
    +digraphs +modify_fname +smartindent +xpm
    +dnd +mouse +startuptime +xsmp_interact
    -ebcdic +mouseshape +statusline +xterm_clipboard
    +emacs_tags +mouse_dec -sun_workshop -xterm_save
    +eval -mouse_gpm +syntax
    +ex_extra -mouse_jsbterm +tag_binary
    +extra_search +mouse_netterm +tag_old_static
    系统 vimrc 文件: "$VIM/vimrc"
    用户 vimrc 文件: "$HOME/.vimrc"
    第二用户 vimrc 文件: "~/.vim/vimrc"
    用户 exrc 文件: "$HOME/.exrc"
    系统 gvimrc 文件: "$VIM/gvimrc"
    用户 gvimrc 文件: "$HOME/.gvimrc"
    第二用户 gvimrc 文件: "~/.vim/gvimrc"
    defaults file: "$VIMRUNTIME/defaults.vim"
    系统菜单文件: "$VIMRUNTIME/menu.vim"
    $VIM 预设值: "/usr/local/share/vim"

Most helpful comment

I had the same issue in both of my computers in different occasions, and this was my solution

if you do in your terminal

vim --version

you can see there that is the apple compiled version
you need the Homebrew compiled version for that you need to
run this in your terminal

brew install vim
brew unlink vim && brew link vim

after this step is important to close all your terminal sessions and start the terminal again.

type

vim --version

and you will see something like this

nosleepfilipe:~ filipedias$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled May  7 2018 03:54:05)
macOS version
Included patches: 1-1800
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               +farsi             +mouse_sgr         -tag_any_white
+arabic            +file_in_path      -mouse_sysmouse    -tcl
+autocmd           +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
....

now you can start your vim normally without the error

All 43 comments

What's the problem with the Issue?

If :YcmToggleLogs returned Not an editor command it probably means YCM has not loaded at all.
You can check that with :scriptnames.

For anything more specific, please fill out the issue template.

I run the command with :scriptnames in my vim and found the result,
~/.vim/bundle/YouCompleteMe/autoload/youcompleteme.vim

Can you paste the output of :messages?

@micbou The result of the :messages is
Traceback (most recent call last): File "<string>", line 19, in <module> File "/home/xw/.vim/bundle/YouCompleteMe/autoload/../python/ycm/setup.py", lin e 37, in SetUpSystemPaths from ycmd import server_utils as su File "/home/xw/.vim/bundle/YouCompleteMe/python/ycm/../../third_party/ycmd/ycm d/server_utils.py", line 26, in <module> import logging File "/home/xw/anaconda2/lib/python2.7/logging/__init__.py", line 26, in <modu le> import sys, os, time, cStringIO, traceback, warnings, weakref, collections File "/home/xw/anaconda2/lib/python2.7/weakref.py", line 14, in <module> from _weakref import ( ImportError: cannot import name _remove_dead_weakref

Do you get the error if you run the command

python -c "import weakref"

in a terminal?

@micbou weakref can be imported.

And what happens if you do

:py import weakref

in Vim?

@micbou the command was run in vim and the message is
Traceback (most recent call last): File "<string>", line 1, in <module> File "/home/xw/anaconda2/lib/python2.7/weakref.py", line 14, in <module> from _weakref import ( ImportError: cannot import name _remove_dead_weakref

We don’t support anaconda. Can you try with standard python?

@micbou @puremourning Thank you very much for your answer. I know it.

@JoeyBoyi Did you fix the issue by using a different Python?

@micbou I haven't tried this method lately.I will solve this issue when I am free.

I seem to be having the same issue, i've been trying to debug it for a while, don't seem to be getting anywhere.
FYI: I'm using standard python in my setup and it still doesn't seem to be working for me

Looking at similar issues on the web, it seems to be caused by having two versions of the Python standard library installed on the system and the Python loaded in Vim picking the wrong one. You should compare the paths of the Python executable and the weakref module inside Vim:

:py print(sys.executable)
:py import weakref

You may have to replace :py with :py3 if using Python 3. The second command should raise the error with the path to the weakref module. What's the result of these two commands?

So the first command returns:

/usr/local/bin/python

And the second command returns:

```java
Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 14, in >
from _weakref import (
ImportError: cannot import name _remove_dead_weakref

Could you now run the command:

/usr/local/bin/python -c "import weakref; print(weakref.__file__)"

in a terminal? If the printed path is not the same as the one shown in the error (/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py) then we have the confirmation that the Python loaded in Vim is using the wrong standard library path.

hmm, so its pointing to a file with the same name but a different extension, seems like the bytecode
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.pyc

I'm having the same issue with the same output as @cnolimit. I'm using a virtualenv, and I used the same virtualenv to run install.py for YCM. My understanding is that because the path in the error is the same as the path from the terminal, Vim is probably using the correct standard library path. Is that accurate? Any other ideas as to what's going on?

Thanks for your time btw!

UPDATE: I was also looking at https://github.com/Valloric/YouCompleteMe/issues/2136
If I deactivate the virtualenv and explicitly set the g:ycm_server_python_interpreter to the path of the virtualenv python I was using when I installed it, suddenly it seems to work. If I re-activate that same virtualenv though, I get this error again.

I'm going to try reinstalling using a different python and setting that python to that executable and running with the virtualenv.

UPDATE: I tried reinstalling using a different python, setting that python to that executable, and running with virtualenv. It seems like YCM works fine if I don't use the virtualenv (and use the default python which I used this time to run install.py), but if I use virtualenv it shows this same error (YouCompleteMe unavailable: cannot import name _remove_dead_weakref)

I'm having a similar issue – not exactly the same but some of the symptoms are the same. For example, running

:py print(sys.executable)
:py import weakref

yields

/usr/local/opt/python@2/bin/python2.7

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/Cellar/python@2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.py", line 14, in <module>
    from _weakref import (
ImportError: cannot import name _remove_dead_weakref

but

❯ /usr/local/opt/python@2/bin/python2.7 -c "import weakref; print(weakref.__file__)"
/usr/local/Cellar/python@2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/weakref.pyc

When I open vim, I see

YouCompleteMe unavailable: dlopen(/usr/local/Cellar/python@2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /usr/local/Cellar/python@2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python@2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
:messages
Messages maintainer: Bram Moolenaar <[email protected]>
Traceback (most recent call last):
  File "<string>", line 19, in <module>
  File "/Users/tupton/.vim/plugged/YouCompleteMe/autoload/../python/ycm/setup.py", line 37, in SetUpSystemPaths
    from ycmd import server_utils as su
  File "/Users/tupton/.vim/plugged/YouCompleteMe/python/ycm/../../third_party/ycmd/ycmd/server_utils.py", line 25, in <module>
    import io
  File "/usr/local/Cellar/python@2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python@2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /usr/local/Cellar/python@2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python@2/2.7.14_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

If this is an entirely separate issue, let me know and I can start a new one and provide more details, but I figured it was at least related enough to ask here first.

I should also note that this seemed to start after homebrew made python the python3 formula and python@2 the python2 formula. I do have python3 installed on my system, but it is not linked or otherwise available anywhere in my PATH.

I had a similar issue when brew updated my python. Re-installing YCM and running brew upgrade macvim solved my issue

My specific issue seems to have been fixed by updating to a later python@2 via Homebrew and re-installing YCM. I'm still not 100% sure why it was broken with the initial python@2 formula.

IIRC I had to use --with-python@2 when brewing macvim recently, having never had to do that before. I'm sure there are good reasons behind the changes, despite them being somewhat, erm, ninja.

After update python@2 by brew, I still have this problem. Did anyone find the solution yet?

Same issue on vim but on neovim it works just fine, python2 upgraded

What issue? If you are having an issue, see CONTRIBUTING.md.

"Me too" doesn't really add anything to the discussion, particularly as the OP here didn't fill out the issue template.

We know that hombrew has changed its default python, which sucks, but i'm sure they have their reasons for that. This will almost certainly cause tons of issues. I had to do some work on my own systems to get things working again (notably, rebuild ycm by running install.py).

However, it would be better to raise an issue, following CONTRIBUTING.md and/or moaning at homebrew.

I don't know if this help. If you are using YCM on mac, you can try to override default vim with
brew install vim -with-override-system-vim
With brew-compiled vim, YCM works normally

I have the same issue, just uninstalls the brewed version of python2 solves it

brew uninstall python@2

Encountered this issue and the comment from @yifeikong fixed my environment. 👍

I have meet the issue, and I have install python by command "brew uninstall python@2". And My computer is mac, I have to remain the python@2. How to solve it?

@XiaohuanIT macOS comes with python 2.7 preinstalled, uninstall the brewed version(python@2) rolls back to macOS's own version of python.

The cannot import name _remove_dead_weakref error can probably be fixed by setting the pythonhome or pythonthreehome options (depending on the version of Python used) to the right Python home in vimrc. Anyway, the issue reported by OP can be reproduced with the command :py import weakref (or :py3 instead of :py) in Vim so it's definitely not an issue with YCM. For people having the same error but unable to reproduce with :py import weakref or :py3 import weakref, feel free to open a new issue.

Well, I had the same issue today.
The solution that use the macvim instead of the system vim is effective for me
Just make an alias in the ~/.bashrc, like this
alias vim="path to your macvim"

@MEGACJH Using macvim is not a solution, it's a workaround.

Anyway, the issue reported by OP can be reproduced with the command :py import weakref (or :py3 instead of :py) in Vim so it's definitely not an issue with YCM.

Solution or not, there's nothing we can do if your Vim installation is broken.

I had the same issue in both of my computers in different occasions, and this was my solution

if you do in your terminal

vim --version

you can see there that is the apple compiled version
you need the Homebrew compiled version for that you need to
run this in your terminal

brew install vim
brew unlink vim && brew link vim

after this step is important to close all your terminal sessions and start the terminal again.

type

vim --version

and you will see something like this

nosleepfilipe:~ filipedias$ vim --version
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled May  7 2018 03:54:05)
macOS version
Included patches: 1-1800
Compiled by Homebrew
Huge version without GUI.  Features included (+) or not (-):
+acl               +farsi             +mouse_sgr         -tag_any_white
+arabic            +file_in_path      -mouse_sysmouse    -tcl
+autocmd           +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
....

now you can start your vim normally without the error

@puremourning thanks, your solution works on my mac

FWIW I no longer build macvim with py2. I accept the default py 3 now. It just requires rebuilding ycmd once.

After uninstall the python@2, you need to rebuilding ycmd.

@kaiyulee , I just uninstall the python@2. I no need rebuilding ycmd.

it seems you need to relink your system python to default version
in my system (centos6.6) , i soft link /usr/local/bin/python to python2.7, which should be python2.6.
and then i got this problem

when i fix this, by link /usr/local/bin/python to python2.6, i got it run correctly

besides, my vim has enabled python2.7 support

Using python 2.6 won't work. We have dropped support for it a while ago.

brew uninstall --ignore-dependencies --force python@2

Was this page helpful?
0 / 5 - 0 ratings