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. https://crt.sh/?q=example.com), so withholding your domain name here does not increase secrecy, but only makes it harder for us to provide help.

My domain is: liamsirkett.com

I ran this command: sudo certbot --nginx -d liamsirkett.com -d www.liamsirkett.com

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/init.py", line 561, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2631, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2291, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/init.py", line 2297, in resolve
module = import(self.module_name, fromlist=['name'], level=0)
File "/usr/lib/python3/dist-packages/certbot/main.py", line 10, in
import josepy as jose
File "/usr/lib/python3/dist-packages/josepy/init.py", line 44, in
from josepy.interfaces import JSONDeSerializable
File "/usr/lib/python3/dist-packages/josepy/interfaces.py", line 8, in
from josepy import errors, util
File "/usr/lib/python3/dist-packages/josepy/util.py", line 4, in
import OpenSSL
File "/usr/lib/python3/dist-packages/OpenSSL/init.py", line 8, in
from OpenSSL import crypto, SSL
File "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 12, in
from cryptography import x509
File "/usr/lib/python3/dist-packages/cryptography/x509/init.py", line 9, in
from cryptography.x509.base import (
File "/usr/lib/python3/dist-packages/cryptography/x509/base.py", line 16, in
from cryptography.x509.extensions import Extension, ExtensionType
File "/usr/lib/python3/dist-packages/cryptography/x509/extensions.py", line 18, in
from cryptography.hazmat.primitives import constant_time, serialization
File "/usr/lib/python3/dist-packages/cryptography/hazmat/primitives/constant_time.py", 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:
DigitalOcean

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

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 https://packages.ubuntu.com/xenial/python3-cffi-backend ?

Perhaps removing and reinstalling it might help.

1 Like

Yes,
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"
/home/ftdeploy/flasktaskr-project/my_venv/lib/python3.5/site-packages/_cffi_backend.cpython-35m-x86_64-linux-gnu.so
/home/djangodeploy/myvenv/lib/python3.6/site-packages/_cffi_backend.cpython-36m-x86_64-linux-gnu.so
/usr/lib/python3/dist-packages/_cffi_backend.cpython-35m-x86_64-linux-gnu.so

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. https://arashmilani.com/post?id=95
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 https://certbot.eff.org/

I will try it. Thanks again.

Hi,
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 https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3.8 get-pip.py
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 !

2 Likes

Congrats and thanks for sharing !!!

I ran:

successfully installed on first shot

pip install -U cffi

I have python3.6.12 installed

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py

followed by

sudo certbot --nginx -d .com -d www..com

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.