azure-search-openai-demo icon indicating copy to clipboard operation
azure-search-openai-demo copied to clipboard

ModuleNotFoundError: No module named '_cffi_backend'

Open marceloricciardi opened this issue 2 years ago • 8 comments

Please provide us with the following information:

This issue is for a: (mark with an x)

- [X] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

Running locally: Run azd login Change dir to app Run ./start.ps1 or ./start.sh or run the "VS Code Task: Start App" to start the project locally.

Any log messages given by the failure

Starting backend

ModuleNotFoundError: No module named 'cffi_backend' thread '' panicked at 'Python API call failed', C:\Users\runneradmin.cargo\registry\src\index.crates.io-6f17d22bba15001f\pyo3-0.18.3\src\err\mod.rs:790:5 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace Traceback (most recent call last): File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\app.py", line 8, in from azure.identity import DefaultAzureCredential File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\backend_env\Lib\site-packages\azure\identity_init.py", line 10, in from .credentials import ( File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\backend_env\Lib\site-packages\azure\identity_credentials_init.py", line 5, in from .authorization_code import AuthorizationCodeCredential File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\backend_env\Lib\site-packages\azure\identity_credentials\authorization_code.py", line 9, in from ..internal.aad_client import AadClient File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\backend_env\Lib\site-packages\azure\identity_internal_init.py", line 5, in from .aad_client import AadClient File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\backend_env\Lib\site-packages\azure\identity_internal\aad_client.py", line 11, in from .aad_client_base import AadClientBase File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\backend_env\Lib\site-packages\azure\identity_internal\aad_client_base.py", line 23, in from .aadclient_certificate import AadClientCertificate File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\backend_env\Lib\site-packages\azure\identity_internal\aadclient_certificate.py", line 7, in from cryptography import x509 File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\backend_env\Lib\site-packages\cryptography\x509_init_.py", line 7, in from cryptography.x509 import certificate_transparency File "C:\Users\A556056\OneDrive - Atos\Documents\Projetos\Pessoal\GitHub\azure-search-openai-demo\app\backend\backend_env\Lib\site-packages\cryptography\x509\certificate_transparency.py", line 11, in from cryptography.hazmat.bindings._rust import x509 as rust_x509 pyo3_runtime.PanicException: Python API call failed

Expected/desired behavior

Successful deployment

OS and Version?

Windows 11

azd version?

azd version 1.0.2

Versions

Python 3.11 - 64 bit

Mention any other details that might be useful

I am trying to run locally following the README instructions and using Azure OpenAI in another resource group. Both are in the same subscription and I am the owner/admin.


Thanks! We'll be in touch soon.

marceloricciardi avatar Jun 20 '23 17:06 marceloricciardi

I have gotten that error a few times. I resolve it by changing my Python setup, like changing what Python version I'm using. Do you know what version you're using now? And can you change to a different version? Another option is to use GitHub Codespaces.

pamelafox avatar Jun 20 '23 17:06 pamelafox

I have gotten that error a few times. I resolve it by changing my Python setup, like changing what Python version I'm using. Do you know what version you're using now? And can you change to a different version? Another option is to use GitHub Codespaces.

Please, what version of Python are you using? I'm on 3.11 (64 bit).

marceloricciardi avatar Jun 20 '23 17:06 marceloricciardi

It just worked for me with Python 3.10 inside a Dev Container. It doesn't work when I use my Mac's standard Python 3.9 installation. I think there may be an issue with the packages installed, there's a number of suggestions in this thread about reinstalling cffi:

https://stackoverflow.com/questions/34370962/no-module-named-cffi-backend

I think it's worth trying those, since Python 3.11 should theoretically be a good version.

pamelafox avatar Jun 20 '23 17:06 pamelafox

It just worked for me with Python 3.10 inside a Dev Container. It doesn't work when I use my Mac's standard Python 3.9 installation. I think there may be an issue with the packages installed, there's a number of suggestions in this thread about reinstalling cffi:

https://stackoverflow.com/questions/34370962/no-module-named-cffi-backend

I think it's worth trying those, since Python 3.11 should theoretically be a good version.

I changed my Python version to 3.10 and the issue is resolved. Thanks @pamelafox !

marceloricciardi avatar Jun 20 '23 17:06 marceloricciardi

Okay great. I'm going to send a PR to update the Dev Container to make it more likely for other folks to not run into this issue, for devs using the Dev Container. Keeping this issue open as reference for that PR.

pamelafox avatar Jun 20 '23 17:06 pamelafox

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this issue will be closed.

github-actions[bot] avatar Sep 01 '23 01:09 github-actions[bot]

@pamelafox ... I faced the same issue. There is a scenario for me which can regenerate the error is: I already deployed the code having python 3.10 on my local. Now when I switched to Python 3.11 and ran "start.ps1" I got this error. Also I got same error when I had to add new file in data folder and ran "azd provision" or in general "azd up". So it was calling scripts at the backend.

Now when I uploaded the new document and tried "azd provision" or "azd up", in this scenario I deleted the virtual env, created during the steps. I re-ran the command after deleting virtual env.

In scenario of running, "start.ps1" I faced the same error and i deleted the virtual environment created their as well. I re-ran and it is resolved.

So I found why it is not working in 3.11 and 3.10 only because the libraries in the virtual environment are support for 3.10 initially and when I switched to 3.11 it was not supported because of already installed libraries.

Piyush-jain-2487 avatar Apr 05 '24 06:04 Piyush-jain-2487