azure功能中的卸载包



我的azure函数应用程序(python)抛出异常:模块类型没有属性'_classVar'。解决这个问题的方法是卸载数据类包。如何使用pip在python azure函数上卸载此包?

如果我运行pip uninstall dataclasses,这会反映在部署上吗?

如果您使用的是python 3.7或更高版本,则需要使用相同的pip uninstall dataclasses卸载dataclass库。

作为数据类包是Python 3.7dataclass功能的后端口。

或者如果你仍然想要dataclasses,你可以将python版本降级到3.6。

更多信息请参考以下链接:

  • 博客AttributeError:模块' typing '没有属性' _ClassVar '

  • <GitHub问题/strong>

我在尝试用Python 3.7环境从azure Devops管道部署azure函数时也遇到了很多麻烦,所以我决定把它放在这里,因为它可能会帮助其他人解决同样的问题。

您需要用您各自的变量准备下面的yaml文件。

trigger:
- {{ branch }}

variables:
# Azure Resource Manager connection created during pipeline creation
azureSubscription: '{{ azureRmConnection.Id }}'

# Function app name
functionAppName: '{{ functionAppName }}'

# Agent VM image name
vmImageName: 'ubuntu-latest'

# Working Directory
workingDirectory: '{{ workingDirectory }}'

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.6'
inputs:
versionSpec: 3.6 # Functions V2 supports Python 3.6 as of today

- bash: |
pip install --target="./.python_packages/lib/site-packages" -r ./requirements.txt
rm -rf ./.python_packages/lib/site-packages/dataclasses-0.6*
rm ./.python_packages/lib/site-packages/dataclasses.py
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'

这些是安装requirements.txt后的关键行。这将从site-packages文件夹中删除包。

rm -rf ./.python_packages/lib/site-packages/dataclasses-0.6*
rm ./.python_packages/lib/site-packages/dataclasses.py

pip uninstall dataclasses将无法工作,因为您不在正确的文件夹中。

希望这对你有帮助!

最新更新