Azure-Samples / azure-search-openai-demo

A sample app for the Retrieval-Augmented Generation pattern running in Azure, using Azure AI Search for retrieval and Azure OpenAI large language models to power ChatGPT-style and Q&A experiences.
https://azure.microsoft.com/products/search
MIT License
5.7k stars 3.84k forks source link

ModuleNotFoundError: No module named '_cffi_backend' #343

Open marceloricciardi opened 1 year ago

marceloricciardi commented 1 year ago

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.

pamelafox commented 1 year ago

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.

marceloricciardi commented 1 year ago

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).

pamelafox commented 1 year ago

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.

marceloricciardi commented 1 year ago

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 !

pamelafox commented 1 year ago

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.

github-actions[bot] commented 11 months ago

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.

Piyush-jain-2487 commented 3 months ago

@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.