Forums

ImportError: cannot import name '_remove_dead_weakref'

I am getting the above error when trying to do anything with Django in my virtualenv.

I first noticed my websites were not working and the error log had the following message:

2020-07-13 02:50:24,611: Error running WSGI application

2020-07-13 02:50:25,285: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.

2020-07-13 02:50:25,286: Did you install mysqlclient?

I tried following debugging instructions here https://help.pythonanywhere.com/pages/DebuggingImportError/
But when I try to do anything with Django I get the following error:

Traceback (most recent call last): File "manage.py", line 8, in <module> from django.core.management import execute_from_command_line File "/home/SirBud/.virtualenvs/projectionsapp-virtualenv/lib/python3.6/site-packages/django/init.py", line 1, in <module> from django.utils.version import get_version File "/home/SirBud/.virtualenvs/projectionsapp-virtualenv/lib/python3.6/site-packages/django/utils/version.py", line 2, in <module> import functools File "/home/SirBud/.virtualenvs/projectionsapp-virtualenv/lib/python3.6/functools.py", line 23, in <module> from weakref import WeakKeyDictionary File "/home/SirBud/.virtualenvs/projectionsapp-virtualenv/lib/python3.6/weakref.py", line 12, in <module> from _weakref import ( ImportError: cannot import name '_remove_dead_weakref' The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 14, in <module> ) from exc ImportError: Couldn't import Django. Are you sure it's installed and available on your PYTHONPATH environment variable? Did you forget to activate a virtual environment?

Are you sure that you run your web app in the same environment that you installed your modules for?

I needed to rebuild my virtualenv, everything is working now.

Great! Glad you found a fix.