ImportError: cannot import name _remove_dead_weakref

Solution 1:

I recently ran into this issue when I was using Pycharm 2017.3.2 on Ubuntu 16.10.

My setup was:

I installed Python 3.6 from the python PPA. I had Python 3.6.0b4. However, I had just upgraded Ubuntu to 17.04, but had yet to reboot. When I rebooted my computer, it still was throwing that error. Therefore, I tried to see what the default python3.6 was in the terminal.

➜  ~ python3.6
Python 3.6.1 (default, Mar 22 2017, 06:17:05) 
[GCC 6.3.0 20170321] on linux
Type "help", "copyright", "credits" or "license" for more information.

Therefore, I realized that the Python that I had in my virtualenv might be outdated or pointing to an incorrect Python version.

Solution:

  • Made sure what version of Python 3.6 I had installed (3.6.1).
  • Removed my virtualenvironment.
  • Created new virtualenvironment using virtualenvwrapper: mkvirtualenv --python=python3.6

  • Installed the requirements with pip: pip install -r requirements.txt

Solution 2:

Happened to me after upgrading to Ubuntu 17.10. I fixed my python 2.7 virtualenv by going to its folder and entering:

virtualenv -p /usr/bin/python2.7 .

Solution 3:

This happened to me after upgrading Ubuntu to 17.10.

I tried to run an application which was installed in a Python virtualenv.

I fixed it like this:

cd my-virtualenv-directory
virtualenv . --system-site-packages

The option --system-site-packages was needed because the application uses python-gtk from Ubuntu. I gues in most other cases it is not needed.

Now ImportError: cannot import name _remove_dead_weakref is gone :-)