英文:
CFFI Backend not found Azure functions
问题
以下是您要翻译的内容:
尝试从Azure DevOps管道部署Azure Python函数。该函数出现错误
> ModuleNotFoundError: No module named _cffi_backend
解释器是正确的。
这是我的 requirements.txt
文件
azure-functions
requests==2.26.0
cffi==1.14.5
azure-storage-blob==12.9.0
在尝试了多种变化之后,这是我最终使用的bash脚本
sudo apt-get install libffi-dev
python -m venv funcenv
source funcenv/bin/activate
pip install --upgrade pip
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
pip install --target="./.python_packages/lib/site-packages" --no-cache-dir cffi
英文:
Trying to deploy an azure python function from an Azure DevOps pipeline. The function gives the error
> ModuleNotFoundError: No module named _cffi_backend
The interpreter is correct.
This is my requirements.txt
azure-functions
requests==2.26.0
cffi==1.14.5
azure-storage-blob==12.9.0
After having trying numerous variations, this is the final bash script I m using
sudo apt-get install libffi-dev
python -m venv funcenv
source funcenv/bin/activate
pip install --upgrade pip
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
pip install --target="./.python_packages/lib/site-packages" --no-cache-dir cffi
答案1
得分: 1
以下是您要求的翻译内容:
"由于您正在使用Azure Devops管道部署带有cffi包的函数,您可以直接使用ubuntu-latest或Linux代理来安装您的包,然后在部署时将它们包含在函数代码目录中,如下所示:"
"我像下面这样安装了所需的库:"
YAML脚本:
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
sudo apt-get install libffi-dev
python -m venv funcenv
source funcenv/bin/activate
pip install --upgrade pip
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
OR
pip install --target="./.python_packages/lib/site-packages" -r .siliconfunc432/requirements.txt
pip install --target="./.python_packages/lib/site-packages" --no-cache-dir cffi
输出:
"在运行上述代码后,您还可以使用以下代码将包复制到您的函数应用目录:"
# 将包复制到函数应用的site-packages目录
cd siliconfunc432
mkdir -p .python_packages/lib/python3.8/site-packages
cp -r ./.python_packages/lib/python3.8/site-packages/* ./.python_packages/lib/site-packages/
然后最终使用以下命令部署您的函数到Azure函数应用:
func azure functionapp publish siliconfunc432 --python
"我也同意@Dean MacGregor,您可以构建一个Docker镜像,并安装cffi库,然后在函数代码中引用该Docker镜像。"
英文:
As you're using an Azure Devops pipeline to deploy your function with cffi package, You can directly use ubuntu-latest or Linux agent to install your packages and then include them in your function code directory while deployment like below:-
I installed the required libraries like below:-
YAML Script:-
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Bash@3
inputs:
targetType: 'inline'
script: |
sudo apt-get install libffi-dev
python -m venv funcenv
source funcenv/bin/activate
pip install --upgrade pip
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
OR
pip install --target="./.python_packages/lib/site-packages" -r .siliconfunc432/requirements.txt
pip install --target="./.python_packages/lib/site-packages" --no-cache-dir cffi
Output:-
After running the above code you can also copy the package to your Function app directory with the code below:-
# Copy packages to function app's site-packages directory
cd siliconfunc432
mkdir -p .python_packages/lib/python3.8/site-packages
cp -r ./.python_packages/lib/python3.8/site-packages/* ./.python_packages/lib/site-packages/
And then finally deploy your Function to Azure function app with the command below:-
func azure functionapp publish siliconfunc432 --python
I also agree to @Dean MacGregor you can build a docker image and install the cffi library and reference that docker image in your function code
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论