Certbot fails due to missing(?) ConfigParser on Debian Stretch

I ran this command: certbot renew --dry-run (installed from official Debian package).

It produced this output:

Traceback (most recent call last):
  File "/usr/bin/certbot", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3019, in <module>
    @_call_aside
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3003, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3032, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 655, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 963, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 849, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'certbot==0.10.2' distribution was not found and is required by the application

My web server is (include version): nginx 1.10.3-1+deb9u1

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

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

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


When I try to remove or re-install certbot, i get the following error; e.g. after a sudo apt update; sudo apt upgrade:

sudo apt update ; and sudo apt upgrade
Hit:1 http://security.debian.org stretch/updates InRelease
Ign:2 http://cdn-fastly.deb.debian.org/debian stretch InRelease                    
Hit:3 http://cdn-fastly.deb.debian.org/debian stretch-updates InRelease
Hit:5 http://apt.armbian.com jessie InRelease                                                  
Hit:4 http://cdn-fastly.deb.debian.org/debian stretch-backports InRelease                      
Hit:6 http://cdn-fastly.deb.debian.org/debian stretch Release
Reading package lists... Done
Building dependency tree       
Reading state information... Done
All packages are up to date.
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] 
Setting up python-certbot-nginx (0.10.2-1) ...
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 35, in <module>
    from debpython.version import SUPPORTED, debsorted, vrepr, \
  File "/usr/share/python/debpython/version.py", line 24, in <module>
    from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg: error processing package python-certbot-nginx (--configure):
 subprocess installed post-installation script returned error exit status 1
Setting up python-configparser (3.3.0r2-2) ...
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 35, in <module>
    from debpython.version import SUPPORTED, debsorted, vrepr, \
  File "/usr/share/python/debpython/version.py", line 24, in <module>
    from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg: error processing package python-configparser (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 python-certbot-nginx
 python-configparser
E: Sub-process /usr/bin/dpkg returned an error code (1)

I very much suspect that the issue is simply that ConfigParser was renamed between Python 2 and 3 and for some reason Certbot doesn’t get the right one.

I already tried to remove and re-install it, but it didn’t help. I have both Python2 and Python3 installed on Debian Stretch.

@hook
For python2.7

apt install python-pip
pip install ConfigParser

But in case of python 3

apt install python3-pip
pip3 install configparser

if You need to fix python default version add alias .

If the above are successfully installed , you can run certbot hassle-free.

Fixing (a bug in) Debian stable certbot with installing dependencies PIP seems a bit hackish. But when your certs are about to expire, a workaround is better than waiting for a proper™ solution :sweat_smile:

So I tried both the pip3 and pip versions and in both certbot still throws the same error.

What is odder still (and I realise that’s a Debian issue, not Certbot’s), is that even if I try to remove the python-configparser from the Debian stable tree, e.g. with dpkg --remove --force-remove-reinstreq python-configparser I get the following error:

(Reading database ... 79797 files and directories currently installed.)
Removing python-configparser (3.3.0r2-2) ...
  File "/usr/bin/pyclean", line 63
    except (IOError, OSError), e:
                             ^
SyntaxError: invalid syntax
dpkg: error processing package python-configparser (--remove):
 subprocess installed pre-removal script returned error exit status 1
Traceback (most recent call last):
  File "/usr/bin/pycompile", line 35, in <module>
    from debpython.version import SUPPORTED, debsorted, vrepr, \
  File "/usr/share/python/debpython/version.py", line 24, in <module>
    from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg: error while cleaning up:
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 python-configparser

And same of course for python-certbot-nginx.

If you run /usr/bin/python, is it Python 2 or Python 3? Does it run at all? What version is it supposed to be?

It looks like apt and Certbot and Python expect /usr/bin/python to be Python 2, but it’s running Python 3, so most Python software is failing. Syntax errors, modules installed for Python 2 but not Python 3 don’t exist, etc.

ConfigParser and configparser are core parts of the Python installation. They can’t possibly not exist, and don’t need to be installed separately. (The reason there are errors about them not existing is that Python 2 programs are being run with with Python 3. The programs aren’t broken, and the module isn’t actually missing, it was just renamed.)

As far as I know, on Debian Stretch, /usr/bin/python should always be Python 2.7. Not Python 3. I could be wrong, but I don’t think so. If there is some sort of supported conversion process, it hasn’t been done completely. (It would have to modify the shebangs in every Python 2 program that uses /usr/bin/python.)

It doesn’t look like anything is wrong with the Certbot package.

1 Like

It seems this was indeed the problem – Python 3 was set as the default.

I followed this howto on changing the default version of Python on Debian Stretch and now it works.

Thank you for your help :smiley:

Great! I’m glad it works now. :smile:

1 Like

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