CFFI后端未找到Azure函数

huangapple go评论70阅读模式
英文:

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

输出:

CFFI后端未找到Azure函数

"在运行上述代码后,您还可以使用以下代码将包复制到您的函数应用目录:"

# 将包复制到函数应用的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:-

CFFI后端未找到Azure函数

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

huangapple
  • 本文由 发表于 2023年4月20日 00:30:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76056867.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定