ImportError: cannot import name _remove_dead_weakref

While trying to renew some of the Let’s Encrypt certs, I got the following error:

$ ./letsencrypt-auto renew
Error: couldn't get currently installed version for /opt/
Traceback (most recent call last):
File "/opt/", line 7, in
from certbot.main import main
File "/opt/", line 6, in
import logging.handlers
File "/usr/lib/python2.7/logging/", line 26, in
import sys, os, time, cStringIO, traceback, warnings, weakref, collections
File "/usr/lib/python2.7/", line 14, in
from _weakref import (
ImportError: cannot import name _remove_dead_weakref

The solution was to execute the following command:

$ mv /opt/ /tmp

The /opt/ directory will be recreated.