部署Azure Function App时遇底层压缩例程加载错误求助
解决Azure Functions部署时"The underlying compression routine could not be loaded correctly"错误
问题场景
在VS Code中执行Azure Functions部署命令:
func azure functionapp publish [the function app name]
出现错误输出:
Getting site publishing info...
[2025-04-23T12:26:20.365Z] Starting the function app deployment...
Creating archive for current directory...
Performing remote build for functions project.
Deleting the old .python_packages directory
The underlying compression routine could not be loaded correctly.
已完成的验证步骤:
- 使用PowerShell的
ls命令确认处于目标函数应用项目目录,项目文件结构符合要求; - 检查host.json、local.settings.json配置无误;
- requirements.txt包含
azure-functions模块; - Azure函数应用与本地项目均使用Python 3.10;
- 确认Azure函数应用环境变量配置齐全;
- 已安装最新版az cli(2.71.0)和Azure Core Tools(4.0.7030);
- 已执行
az login完成登录。
解决方案
1. 修复本地压缩库依赖
该错误多与系统压缩库(如zlib)加载失败相关,针对不同系统操作:
- Windows系统:
- 安装对应Python版本的Visual C++ Redistributable运行时库;
- 重启VS Code和PowerShell终端,确保环境变量生效;
- Linux/macOS系统:
- 安装zlib库:Debian/Ubuntu执行
sudo apt-get install zlib1g-dev,macOS执行brew install zlib; - 重新安装Python 3.10,确保编译时正确链接zlib库。
- 安装zlib库:Debian/Ubuntu执行
2. 改用本地构建部署
跳过远程构建的压缩环节,先本地构建再部署:
- 本地构建项目:
func pack --build-native-deps --python
- 部署构建好的压缩包:
az functionapp deployment source config-zip -g <resource-group-name> -n <function-app-name> --src .\<your-pack-file>.zip
3. 清理缓存与临时文件
- 删除项目目录下的
.python_packages、__pycache__文件夹; - 删除Azure Core Tools临时缓存:
- Windows路径:
%LOCALAPPDATA%\AzureFunctionsTools - Linux/macOS路径:
~/.azurefunctions
- Windows路径:
- 重新执行部署命令。
4. 降级Azure Core Tools版本
新版本工具可能存在压缩库兼容性问题,尝试降级到稳定版本:
- 卸载当前版本:
npm uninstall -g azure-functions-core-tools@4
- 安装指定稳定版本:
npm install -g azure-functions-core-tools@4.0.6518 --unsafe-perm true
内容的提问来源于stack exchange,提问作者ralhpq1
相关产品推荐
相关产品推荐

