英文:
Function App deployment succeeds but fails to import packages (python, linux, consumption plan)
问题
Local deployment directly of a function app using vscode succeeds and the function app works, however when trying to build and deploy through Azure Devops, the deployment succeeds but there is an error when importing numpy.
Result: Failure Exception: ImportError: 无法导入所需的依赖项:numpy:重要提示:请阅读以下内容,了解如何解决此问题!导入 numpy C-扩展失败。此错误可能出现的原因有很多,通常是由于设置问题或 NumPy 安装方式不正确引起的。我们已经编制了一些常见原因和故障排除提示,请参阅:https://numpy.org/devdocs/user/troubleshooting-importerror.html 请注意并检查以下内容:* Python 版本为:Python3.10,来自 "/usr/local/bin/python" * NumPy 版本为:"1.25.0" 请确保它们是您所期望的版本。请仔细阅读上面链接的文档,以获取进一步的帮助。原始错误为:没有名为 'numpy.core._multiarray_umath' 的模块。请检查 requirements.txt 文件以查找缺少的模块。有关更多信息,请参阅故障排除指南:https://aka.ms/functions-modulenotfound
azure-pipelines.yml is very similar to examples, install dependencies and zip:
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'azureSubscription'
# Agent VM image name
vmImageName: 'ubuntu-20.04'
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x' # string. Required. Version spec. Default: 3.x.
architecture: 'x64' # 'x86' | 'x64'. Required. Architecture. Default: x64.
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- task: AzureFunctionApp@2
inputs:
azureSubscription: 'azureSubscription'
appType: 'functionAppLinux'
appName: 'app-name'
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
deploymentMethod: 'auto'
The code is then deployed to the function:
steps:
- task: AzureFunctionApp@2
displayName: 'Azure Function App Deploy'
inputs:
azureSubscription: 'azureSubscription'
appType: functionAppLinux
appName: 'app-name'
package: '$(System.DefaultWorkingDirectory)/_Function App/drop/*zip'
deploymentMethod: zipDeploy
Any help much appreciated, have spent hours looking at examples and reading through the documentation but still haven't got this working. Cheers.
英文:
Local deployment directly of a function app using vscode succeeds and the function app works, however when trying to build and deploy through Azure Devops, the deployment succeeds but there is an error when importing numpy.
Result: Failure Exception: ImportError: Unable to import required dependencies: numpy: IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE! Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed. We have compiled some common reasons and troubleshooting tips at: https://numpy.org/devdocs/user/troubleshooting-importerror.html Please note and check the following: * The Python version is: Python3.10 from "/usr/local/bin/python" * The NumPy version is: "1.25.0" and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help. Original error was: No module named 'numpy.core._multiarray_umath' . Please check the requirements.txt file for the missing module. For more info, please refer the troubleshooting guide: https://aka.ms/functions-modulenotfound
azure-pipelines.yml is very similar to examples, install dependencies and zip:
variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: 'azureSubscription'
# Agent VM image name
vmImageName: 'ubuntu-20.04'
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion@0
inputs:
versionSpec: '3.x' # string. Required. Version spec. Default: 3.x.
architecture: 'x64' # 'x86' | 'x64'. Required. Architecture. Default: x64.
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- task: AzureFunctionApp@2
inputs:
azureSubscription: 'azureSubscription'
appType: 'functionAppLinux'
appName: 'app-name'
package: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
deploymentMethod: 'auto'
The code is then deployed to the function:
steps:
- task: AzureFunctionApp@2
displayName: 'Azure Function App Deploy'
inputs:
azureSubscription: 'azureSubscription'
appType: functionAppLinux
appName: 'app-name'
package: '$(System.DefaultWorkingDirectory)/_Function App/drop/*zip'
deploymentMethod: zipDeploy
Any help much appreciated, have spent hours looking at examples and reading through the documentation but still haven't got this working. Cheers.
答案1
得分: 0
为了解决您的错误,请确保在您的Azure Function存储库的requirements.txt文件中指定以下NumPy版本:
NumPy版本为:"1.25.0"
并在您的YAML脚本中将Python版本设置为3.10,如下所示:
我的requirements.txt:
azure-functions
numpy==1.25.0
我的YAML管道脚本:
trigger:
- master
variables:
azureSubscription: 'subscription-id'
functionAppName: 'siliconfunc56'
vmImageName: 'ubuntu-latest'
workingDirectory: '$(System.DefaultWorkingDirectory)'
stages:
- stage: Build
displayName: 构建阶段
jobs:
- job: Build
displayName: 构建
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: '构建扩展'
- task: UsePythonVersion@0
displayName: '使用Python 3.10'
inputs:
versionSpec: 3.10
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
workingDirectory: $(workingDirectory)
displayName: '安装应用程序依赖项'
- task: ArchiveFiles@2
displayName: '归档文件'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: 部署阶段
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: 部署
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
displayName: 'Azure函数应用程序部署'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionAppLinux
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
输出:
Portal:
英文:
In order to resolve your error make sure you have
The NumPy version is: "1.25.0
specified in your requirements.txt file in your Azure Function repository. And In your YAML Script set the Python version in UsePythonVersion@0 to 3.10 like my script below:-
My requirements.txt:-
azure-functions
numpy==1.25.0
My YAML pipeline script:-
trigger:
- master
variables:
azureSubscription: 'subscription-id'
functionAppName: 'siliconfunc56'
vmImageName: 'ubuntu-latest'
workingDirectory: '$(System.DefaultWorkingDirectory)'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- bash: |
if [ -f extensions.csproj ]
then
dotnet build extensions.csproj --runtime ubuntu.16.04-x64 --output ./bin
fi
workingDirectory: $(workingDirectory)
displayName: 'Build extensions'
- task: UsePythonVersion@0
displayName: 'Use Python 3.10'
inputs:
versionSpec: 3.10
- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
workingDirectory: $(workingDirectory)
displayName: 'Install application dependencies'
- task: ArchiveFiles@2
displayName: 'Archive files'
inputs:
rootFolderOrFile: '$(workingDirectory)'
includeRootFolder: false
archiveType: zip
archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
replaceExistingArchive: true
- publish: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
artifact: drop
- stage: Deploy
displayName: Deploy stage
dependsOn: Build
condition: succeeded()
jobs:
- deployment: Deploy
displayName: Deploy
environment: 'development'
pool:
vmImage: $(vmImageName)
strategy:
runOnce:
deploy:
steps:
- task: AzureFunctionApp@1
displayName: 'Azure functions app deploy'
inputs:
azureSubscription: '$(azureSubscription)'
appType: functionAppLinux
appName: $(functionAppName)
package: '$(Pipeline.Workspace)/drop/$(Build.BuildId).zip'
Output:-
Portal:-
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论