相关文章推荐
豪气的红豆  ·  fgbg = ...·  6 月前    · 
刚毅的长颈鹿  ·  java - all ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

I had to uninstall cffi first (pip uninstall cffi) and then reinstall again, because it said it was already installed – Thomas Jul 10, 2018 at 13:38

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
                Just reinstalling did it for me. (ran into the error after downgrading fabric from 2.x to 1.x)
– Smittie
                Apr 18, 2022 at 19:45

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.

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

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.

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.

It was happening to me in a venv with Python 3.6 and I removed it and replaced it with a venv with Python 3.8 in my Ubuntu 20.04 and everything worked and all the problems were gone. Your answer inspired me to try a clean, radical solution. Thanks @Jurrian – Carles Mateo Sep 2, 2021 at 10:24

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

Could you provide more information regarding the structure of your layer? like where you uncompress the whl file? – Jun Sep 11, 2021 at 0:13

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.

While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Tyler2P Aug 9, 2021 at 9:30

I got this issue running an Ansible playbook using python 3.9 under Ubuntu-18.04 in WSL2. It was sorted by doing:

sudo apt-get remove -y python3-cffi-backend
sudo apt-get install -y python3-cffi-backend

I had the same problem. I have uninstalled the cffi and then installed it and it was solved:

pip uninstall cffi
pip install cffi
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.