ModuleNotFoundError: No module named '_cffi_backend'

Please fill out the fields below so we can help you better. Note: you must provide your domain name to get help. Domain names for issued certificates are all made public in Certificate Transparency logs (e.g., so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is:

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

It produced this output:
Traceback (most recent call last):
File "/usr/bin/certbot", line 11, in
load_entry_point('certbot==0.31.0', 'console_scripts', 'certbot')()
File "/usr/lib/python3/dist-packages/pkg_resources/", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/", line 2631, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/", line 2291, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/", line 2297, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/lib/python3/dist-packages/certbot/", line 10, in
import josepy as jose
File "/usr/lib/python3/dist-packages/josepy/", line 44, in
from josepy.interfaces import JSONDeSerializable
File "/usr/lib/python3/dist-packages/josepy/", line 8, in
from josepy import errors, util
File "/usr/lib/python3/dist-packages/josepy/", line 4, in
import OpenSSL
File "/usr/lib/python3/dist-packages/OpenSSL/", line 8, in
from OpenSSL import crypto, SSL
File "/usr/lib/python3/dist-packages/OpenSSL/", line 12, in
from cryptography import x509
File "/usr/lib/python3/dist-packages/cryptography/x509/", line 9, in
from cryptography.x509.base import (
File "/usr/lib/python3/dist-packages/cryptography/x509/", line 16, in
from cryptography.x509.extensions import Extension, ExtensionType
File "/usr/lib/python3/dist-packages/cryptography/x509/", line 18, in
from cryptography.hazmat.primitives import constant_time, serialization
File "/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/", line 9, in
from cryptography.hazmat.bindings._constant_time import lib
ModuleNotFoundError: No module named '_cffi_backend'

My web server is (include version):
Django 2 app using gunicorn & nginx

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

My hosting provider, if applicable, is:

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):
***generates the same error as above:
ModuleNotFoundError: No module named '_cffi_backend'

Is python3-cffi-backend correctly installed?

 dpkg -l | grep "python3-cffi*"

ii python3-cffi 1.10.0-0.1+ubuntu16.04.1+certbot+1 all Foreign Function Interface for Python 3 calling C code
ii python3-cffi-backend 1.10.0-0.1+ubuntu16.04.1+certbot+1 amd64 Foreign Function Interface for Python 3 calling C code - runtime

I think it might be because I have both Python 3.5 & 3.6 on my system.
ls -l /usr/bin/python3.?
-rwxr-xr-x 2 root root 4460304 Oct 9 12:55 /usr/bin/python3.5
-rwxr-xr-x 2 root root 4727904 Aug 17 22:43 /usr/bin/python3.6

But, I'm not certain. Will be back later to try and completely remove python 3.5 from my system. The Django/Flask apps I have running, I believe are all using 3.6. Will have to confirm before proceeding. And, any suggestions you have would be appreciated.
Will be back later to work on it.

Did you install certbot through the PPA perhaps? Because your version (I'm not that familiair with how Ubuntu codes its versions though) contains "certbot" in it..

Also, the currently most recent version of that package is 1.5.2 according to ?

Perhaps removing and reinstalling it might help.

1 Like

sudo add-apt-repository ppa:certbot/certbot

Thanks for the suggestion. I will do it when I get back. Thanks again.

Don't know if this is causing the problem. Or, if my version isn't the newest like you suggested.

sudo find / -name "cffi_backend"

Uninstalled and reinstalled the packages, but no luck, same error. Will revisit this tomorrow and see if there is another way to use Let'sEncrypt (certbot) by reinstalling another way (avoid the PPA, like you mentioned). I'm not sure yet. But, will attack it tomorrow.

Reverted back to HTTP for my sites, to get them working. Found a site that describes certbot installation without the PPA.
Will do that next. Thanks again for your suggestions.

Certbot-auto is being deprecated. I would advice against it. It's probably better to use the certbot snap if you want an alternative for the PPA, see the instructions on

I will try it. Thanks again.

I've had the same issue since few days and I've just resolved it !

I had to install cffi :
pip install -U cffi

But in my case, I got a new error... :face_with_symbols_over_mouth:
AttributeError: module 'platform' has no attribute 'linux_distribution'

To resolve it, I reinstalled pip for python 3.8 like this :
curl -o
pip --version

Then retry
pip install -U cffi

Then a certbot renew --dry-run finally succeeded :slight_smile:

Hope this will work for you to !

1 Like

Congrats and thanks for sharing !!!

I ran:

successfully installed on first shot

pip install -U cffi

I have python3.6.12 installed

curl -o

followed by

sudo certbot --nginx -d .com -d

And, it ran without generating an error.

Thanks again and I hope you have a great day!

Sorry for the large bold text. I didn't know that the number signs I use for comments are interpreted as large bold text.

Glad it worked for you to :+1:

FWIW, this usually happens from two situations:

1- You upgraded an existing Python install without upgrading the site packages. For example: if you are on Python 3.8.5 and upgrade to 3.8.6, you need to upgrade all the site packages that have C extensions because the bindings are usually not compatible and need to be rebuilt.

2- You added a new Python install, your environment is referencing the new version, but the supporting packages are installed in the old environment. For example, you can have Python 3.6 and 3.8 installed side-by-side, and for whatever reasons, your environment tries to run certbot installed under 3.6 with the 3.8 interpreter.

1 Like

Thanks for the explanation. I will keep that in mind going forward.

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