1

All, My Azure Function is Failing with error :

ModuleNotFoundError: No module named '_cffi_backend

Here is my requirement.txt file

azure-functions
azure-functions-durable
azure-identity
azure-storage-blob
requests
python-dateutil
cffi

My requirement file has cffi package and using devops pipeline these package get installed at runtime, generate .zip for azure functions. But its still failing.

I have tried by providing version number as well(PFB) still no luck.

azure-core==1.19.0
azure-storage-blob==12.9.0
azure-storage-file-datalake==12.4.0
certifi==2021.5.30
cffi==1.14.6
charset-normalizer==2.0.6
cryptography==35.0.0
idna==3.2
isodate==0.6.0
msrest==0.6.21
oauthlib==3.1.1
pycparser==2.20
requests==2.26.0
requests-oauthlib==1.3.0
six==1.16.0
urllib3==1.26.7
msal

Can someone help?

2 Answers2

1

ModuleNotFoundError: No module named '_cffi_backend

After checking the error from my end,

Need to check:

  1. The installed cffi version should be compatible with the Python version, as "cffi==1.14.6" was only officially supported up to Python 3.6.

Using python 3.8 and install the latest version of cffi (2.21):

enter image description here

2.The pip version must also be updated to avoid errors like "ModuleNotFoundError:" type to occur as it contains all python packages&modules.

pip Upgrader:

    pip install pip-upgrader
  

An interactive pip requirements upgrader. It also updates the version in your requirements.txt file.

After installed and checked the above reasons, I am able to execute the function successfully without any error.

requirements.txt file:

enter image description here

init.py file:

enter image description here

If required, deploy to the Azure portal to verify it using the "publish" command.

Jahnavi
  • 3,076
  • 1
  • 3
  • 10
  • thank you for your response Jahnavi, I am using python 3.8 now and using cffi 2.21. Also I have added 'pip install pip-upgrader' in my DevOps pipeline , still no luck :( Here is my requirement.txt now (azure-functions azure-functions-durable azure-identity azure-storage-blob requests python-dateutil cffi) – Tushar Zaware Oct 26 '22 at 21:41
  • also when I try run this function locally, I get error: ErrorCode:AuthorizationPermissionMismatch and cffi error when try to run using azure portal – Tushar Zaware Oct 26 '22 at 22:18
  • *ErrorCode:AuthorizationPermissionMismatch* : You need to set the required [roles](https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles) in azure portal to run functions locally. Have you done that? – Jahnavi Oct 27 '22 at 04:06
  • Alternative to check [module not found error](https://blog.finxter.com/fixed-modulenotfounderror-no-module-named-cffi/) – Jahnavi Oct 27 '22 at 04:24
  • It seems issue is with my docker image. I was using ubuntu when I switch it to windows cffi error gone but now I am getting some other error. :( ImportError: cannot import name 'ObjectIdentifier' from 'cryptography.hazmat.bindings._rust' How should we check what configuration my function would need when I have to run the same on Azure and not local system? – Tushar Zaware Oct 27 '22 at 11:55
  • [Refer SO thread](https://stackoverflow.com/questions/50205819/cffi-fails-in-python-linux-virtual-environment-attempting-to-install-crypto) given by @murmur0m – Jahnavi Oct 27 '22 at 12:06
0

I encountered this issue. The rootcause was a discrepancy between the python version setup in the Azure Function and the python version used in the devops deployment pipeline. The Devops pipeline used python 3.9 and Azure function was using 3.10.

I modified the python version in the Az function by going to configurations -> general settings -> stack and changed it to 3.9. This fixed my issue.

Sudharshann D
  • 935
  • 9
  • 9