PIP (Python) : ImportError: cannot import name _remove_dead_weakref

I have encountered the similar issue on my macOS X when I run lldb from the terminal. The error message is the following,

16:55 $ lldb
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/local/Cellar/python@2/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 52, in <module>
    import weakref
File "/usr/local/Cellar/python@2/2.7.14_3/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

The error message is quite similar with yours. This is what I solved on my macOS X.

$ brew list
...<many libraries>
python@  <The one has conflicted with my python3.6>

$ brew remove python@2 --ignore-dependencies
Uninstalling /usr/local/Cellar/python@2/2.7.14_3... (4,662 files, 82.8MB)

I think the problem is caused by the system installed python, which conflicts with personally installed python. After I removed my python2.7 and lldb works well. I hope it will give you some idea, although we are running on a different OS.


To manage different version of python, I recommend you to install pyenv, see here. It can easily switch the different versions of your python.