No module named _cffi_backend

PythonPython 2.6Python Cffi

Python Problem Overview


I have Python 2.6 in my Linux rhel-5. I have installed pip and required CFFI packages. When I try to run a sample CFFI program:

ffi = FFI()

it says:

File "/usr/lib/python2.6/site-packages/cffi/api.py", line 56, in __init__
    import _cffi_backend as backend
ImportError: No module named _cffi_backend

What could be the possible error? Did I miss something during installation? I have installed pip, wheel, pycparser, pytest and cffi.

Python Solutions


Solution 1 - Python

For python2.x use following command:

python -m pip install cffi

for python3.x

python3 -m pip install cffi

Solution 2 - Python

I needed to uninstall and install it again:

sudo pip uninstall cryptography

sudo pip uninstall paramiko

then install pagamiko again

sudo pip install paramiko

and it start to work for me

Solution 3 - Python

I recently had the same issue and none of the above solutions worked for me.

Here is what worked.

sudo apt remove python3-cffi
sudo python3 -m pip install cffi

Solution 4 - Python

Did you compile Python from source, and if so, did it give you any errors during the configure/make/make install phase? Compiling Python from source can be a real beast on older Red Hat systems, so if you installed that way, I'd suggest combing through the configure and make output to be sure that no modules were left out.

In order to get pip install cffi to succeed with no errors, I had to install gcc and libffi-devel from the EL5 repos. From there, I was able to instantiate an FFI instance with no problems:

>>> from cffi import FFI
>>> ffi = FFI()
>>>

Here's the output of pip freeze, for reference:

[root@machine ~]# pip freeze
argparse==1.2.1
autobahn==0.8.10
cffi==1.5.2
characteristic==14.3.0
pika==0.9.13
pyasn1==0.1.7
pyasn1-modules==0.0.8
pycparser==2.14
pycrypto==2.6.1
pyOpenSSL==0.12
pysnmp==4.2.5
requests==2.7.0
service-identity==14.0.0
six==1.7.3
Twisted==14.0.0
version-utils==0.2.2
wheel==0.24.0
zope.interface==4.1.1

If you've got the same or better versions of the relevant packages installed, I'd try a pip -vvv install --upgrade --force-reinstall cffi, just to see if there are perhaps errors that pip was masking, and go from there.

Solution 5 - Python

You have to first remove the following packages:

cryptography
bcrypt
paramiko

Now use the following command to install:

pip -vvv install --upgrade --force-reinstall cffi

Solution 6 - Python

Have the same problem. After many attempts adding import cffi solve the issue.

Make sure you have cffi and cryptography installed.

Solution 7 - Python

I had the same problem, following this thread https://github.com/pyca/cryptography/issues/4403, I solved the problem by reinstalling and upgrading with the command:

pip install -U cffi

Solution 8 - Python

You could look at the code L56 in /usr/lib/python2.6/site-packages/cffi/api.py

It needs the _cffi_backend.so in your pythonpath. You could install the python-cffi for it. But not sure whether it is in your RPM repo, especially you are using RHEL-5. Here is an RPM for CENTOS http://cbs.centos.org/koji/rpminfo?rpmID=20613 Hope it helps. I am still searching the source code for building the _cffi_backend.so.

Solution 9 - Python

For me there was no way to install cffi on python3.8 because of this:

ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)

Somehow, the package python3-distutils does not exist in Ubuntu 16.04.

So I ended up installing python3.7 and now I finally could install cffi, fixing the problem mentioned by the TS.

Solution 10 - Python

You should install cffi via pip install cffi to get the latest version. I had to restart my application for it to recognize the cffi installation.

Solution 11 - Python

I was getting this error while trying to get the cryptography module to work with Python 3.8 for AWS Lambda.

Adding the cffi*manylinux*.whl files to my Lambda Layer (as suggested here) worked.

The cffi module comes built in for many python distributions, but not on AWS Lambda

Solution 12 - Python

For AWS Lambda I was facing the same issue when running on Python3.7. When I downgraded it to Python3.6, this issue was resolved.

I think this packaged might have been present in Python3.6 version and later was removed. Adding this package while making layers for AWS Lambda might resolve the problem for Python3.7.

Solution 13 - Python

I encountered this issue when trying to install packages in a local directory using pip install -t . and then running python (2.7). My solution was to remove the -t and not install into a local directory.

Solution 14 - Python

it worked after adding " import cffi " in my application.

please refer for more details. https://buildmedia.readthedocs.org/media/pdf/cffi/latest/cffi.pdf

Solution 15 - Python

Thanks to @MPlanchard, for his answer which helped identify the cause

In my case, the issue was related to python3.9, changing to python3.8 it just works well!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAshView Question on Stackoverflow
Solution 1 - PythonBhavesh OdedraView Answer on Stackoverflow
Solution 2 - Pythonuser6640657View Answer on Stackoverflow
Solution 3 - PythonHugues BONIView Answer on Stackoverflow
Solution 4 - PythonMPlanchardView Answer on Stackoverflow
Solution 5 - PythonPavel GromovView Answer on Stackoverflow
Solution 6 - PythonAntonioView Answer on Stackoverflow
Solution 7 - PythonDvdGView Answer on Stackoverflow
Solution 8 - PythonKasperView Answer on Stackoverflow
Solution 9 - PythonJurrianView Answer on Stackoverflow
Solution 10 - PythonB. LatifView Answer on Stackoverflow
Solution 11 - Pythonmb_atxView Answer on Stackoverflow
Solution 12 - Pythonsam agrawalView Answer on Stackoverflow
Solution 13 - PythonGabe NodarseView Answer on Stackoverflow
Solution 14 - PythonMahesh TawadeView Answer on Stackoverflow
Solution 15 - PythonnormalUserView Answer on Stackoverflow