Windows 10系统Python 3.10环境安装pyodbc失败报错问题
Pyodbc安装报错解决方案
问题描述
安装Pyodbc时抛出VC版本依赖错误,设备上已安装Visual Studio,且包含Microsoft Visual C 12、15-19版本,仍无法正常安装,完整错误日志如下:
Running setup.py clean for pyodbc Failed to build pyodbc Installing collected packages: sqlparse, pytz, asgiref, pyodbc, Django, Pillow, mssql-django, django-crispy-forms Running setup.py install for pyodbc ... error ERROR: Command errored out with exit status 1: command: 'C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Athar\\AppData\\Local\\Temp\\pip-install-w0wwm18g\\pyodbc_61963e883a8543fea24a63b1c522bbea\\setup.py'"'"'; __file__='"'"'C:\\Users\\Athar\\AppData\\Local\\Temp\\pip-install-w0wwm18g\\pyodbc_61963e883a8543fea24a63b1c522bbea\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Athar\AppData\Local\Temp\pip-record-t1td50y6\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\include\site\python3.10\pyodbc' cwd: C:\Users\Athar\AppData\Local\Temp\pip-install-w0wwm18g\pyodbc_61963e883a8543fea24a63b1c522bbea\ Complete output (7 lines): running install C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\lib\site-packages\setuptools\command\install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools. warnings.warn( running build running build_ext building 'pyodbc' extension error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/ ---------------------------------------- ERROR: Command errored out with exit status 1: 'C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Athar\\AppData\\Local\\Temp\\pip-install-w0wwm18g\\pyodbc_61963e883a8543fea24a63b1c522bbea\\setup.py'"'"'; __file__='"'"'C:\\Users\\Athar\\AppData\\Local\\Temp\\pip-install-w0wwm18g\\pyodbc_61963e883a8543fea24a63b1c522bbea\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\Athar\AppData\Local\Temp\pip-record-t1td50y6\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\Athar\Desktop\New folder\Project\HeatlhCare\venv\include\site\python3.10\pyodbc' Check the logs for full command output.
解决方案
- 升级pip到最新版本:旧版本pip无法拉取对应Python版本的pyodbc预编译二进制包,会触发源码编译逻辑才会校验VC++依赖,执行
python -m pip install --upgrade pip升级后重试即可解决90%以上同类问题。 - 补全Visual Studio C编译组件:打开Visual Studio Installer,选择修改现有安装,在工作负载标签页勾选「使用C的桌面开发」,等待组件安装完成后重启设备再尝试安装。
- 直接使用预编译wheel包:无需本地编译,可直接下载适配你Python版本、系统架构的pyodbc wheel安装包,通过
pip install xxx.whl命令直接安装,全程不需要VC++编译环境。 - 排查虚拟环境异常:当前报错是在虚拟环境中触发,可尝试新建干净的虚拟环境,或先在全局Python环境安装pyodbc,再将全局目录下的pyodbc相关文件复制到虚拟环境的site-packages目录中。
内容的提问来源于stack exchange,提问作者umair mehmood
相关产品推荐
相关产品推荐

