在VS Code中运行Azure无服务器函数时pyodbc wheel构建失败
在Win11+VS Code中运行Azure无服务器函数时pyodbc安装失败的解决建议
环境信息
- Win11
- Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64)
- Python 3.11
- pip 23.0.1
问题详情
克隆GitHub仓库并安装Azure相关扩展后,在VS Code中启动调试时,触发pip install -r requirements.txt执行失败,核心错误出在pyodbc的安装环节:
无--use-pep517参数时的报错
Installing collected packages: pyodbc, certifi, azure-functions, xmltodict, urllib3, six, numpy, idna, colorama, charset-normalizer, requests, python-dateutil, click, stripe, pandas, kml2geojson Attempting uninstall: pyodbc Found existing installation: pyodbc 4.0.35 Uninstalling pyodbc-4.0.35: Successfully uninstalled pyodbc-4.0.35 DEPRECATION: pyodbc is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559 Running setup.py install for pyodbc ... error error: subprocess-exited-with-error × Running setup.py install for pyodbc did not run successfully.
添加--use-pep517参数后的报错
ERROR: Failed building wheel for pyodbc Failed to build pyodbc ERROR: Could not build wheels for pyodbc, which is required to install pyproject.toml-based projects
关键现象:单独执行pip install pyodbc可正常完成安装。
相关配置
requirements.txt
azure-functions==1.8.0 certifi==2021.10.8 charset-normalizer==2.0.9 idna==3.3 pyodbc==4.0.32 requests==2.26.0 stripe==2.64.0 urllib3==1.26.7 pandas==1.3.5 xmltodict==0.12.0 kml2geojson==5.0.1
local.settings.json
{ "IsEncrypted": false, "Values": { "FUNCTIONS_WORKER_RUNTIME": "python", "server":"RAZERPRO17", "database" : "MyDatabase", "uname" : "MyUser", "password" : "MyPassword", "stripe_api_key" : "sk_test_.........", "google_map_id" : "https://www.google.com/maps/d/u/0/embed?mid=....... }
host.json
{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[1.*, 2.0.0)" } }
解决建议
1. 先安装wheel包再执行依赖安装
报错提示wheel未安装导致pyodbc使用legacy方式安装,先全局安装wheel:
pip install wheel
再重新执行:
pip install -r requirements.txt
2. 替换requirements中的pyodbc版本
既然单独安装pyodbc可成功,先查看当前安装的版本:
pip show pyodbc
将requirements.txt里的pyodbc==4.0.32替换为实际成功安装的版本(比如报错中提到的4.0.35),再重新执行依赖安装。
3. 确认VS Code的Python解释器配置
确保VS Code选中的解释器是C:\Python311,避免因虚拟环境或其他版本导致依赖路径不一致:
- 按
Ctrl+Shift+P,输入Python: Select Interpreter,选择C:\Python311\python.exe
4. 手动预安装指定版本pyodbc
先手动安装requirements中指定的pyodbc版本:
pip install pyodbc==4.0.32
再执行pip install -r requirements.txt,此时pip会跳过已安装的pyodbc,直接处理其他依赖。
5. 禁用VS Code调试自动构建
若以上方法无效,可暂时禁用调试时的自动依赖安装,手动完成安装后再启动调试:
- 在VS Code设置中搜索
Azure Functions: Python Build,取消勾选Auto Build选项,手动执行pip install -r requirements.txt后再启动调试。
内容的提问来源于stack exchange,提问作者Aaron Reese
相关产品推荐
相关产品推荐

