ImportError: cannot import name 'Mapping' from 'collections'

My domain is:

I ran this command:
sudo certbot --nginx -d -d

It produced this output:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/pytz/", line 3, in
from UserDict import DictMixin
ModuleNotFoundError: No module named 'UserDict'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/bin/certbot", line 33, in
sys.exit(load_entry_point('certbot==1.21.0', 'console_scripts', 'certbot')())
File "/usr/bin/certbot", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.10/importlib/metadata/", line 171, in load
module = import_module('module'))
File "/usr/lib/python3.10/importlib/", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1006, in _find_and_load_unlocked
File "", line 688, in _load_unlocked
File "", line 883, in exec_module
File "", line 241, in _call_with_frames_removed
File "/usr/lib/python3/dist-packages/certbot/", line 2, in
from certbot._internal import main as internal_main
File "/usr/lib/python3/dist-packages/certbot/_internal/", line 23, in
from certbot import configuration
File "/usr/lib/python3/dist-packages/certbot/", line 8, in
from certbot import util
File "/usr/lib/python3/dist-packages/certbot/", line 25, in
from certbot._internal import constants
File "/usr/lib/python3/dist-packages/certbot/_internal/", line 6, in
from acme import challenges
File "/usr/lib/python3/dist-packages/acme/", line 24, in
from acme import fields
File "/usr/lib/python3/dist-packages/acme/", line 8, in
import pyrfc3339
File "/usr/lib/python3/dist-packages/pyrfc3339/", line 17, in
from pyrfc3339.generator import generate
File "/usr/lib/python3/dist-packages/pyrfc3339/", line 1, in
import pytz
File "/usr/local/lib/python3.10/dist-packages/pytz/", line 37, in
from pytz.lazy import LazyDict, LazyList, LazySet
File "/usr/local/lib/python3.10/dist-packages/pytz/", line 5, in
from collections import Mapping as DictMixin
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/

My web server is (include version): nginx (ubuntu 20.04)

The operating system my web server runs on is (include version):

My hosting provider, if applicable, is: digitalocean

I can login to a root shell on my machine (yes or no, or I don't know):

I'm using a control panel to manage my site (no, or provide the name and version of the control panel):

The version of my client is (e.g. output of certbot --version or certbot-auto --version if you're using Certbot):

You have installed pytz via pip and it has caused problems for your local Python installation. Almost always, installing packages globally via pip is a bad idea.

You can try remove that version of pytz and try again with the version you get from the Ubuntu repositories:

python3 -m pip uninstall pytz
apt-get --reinstall install python3-tz

Thank you it is now fixed!


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.