我正在尝试安装pyodbc。我有python 3.12和VS 2022。我已经下载了微软c++构建工具VS.当我运行"pip安装pyodbc"我得到以下错误:
Defaulting to user installation because normal site-packages is not writeable
Collecting pyodbc
Using cached pyodbc-4.0.35.tar.gz (273 kB)
Installing build dependencies ... done
Getting requirements to build wheel ... done
Installing backend dependencies ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: pyodbc
Building wheel for pyodbc (pyproject.toml) ... error
error: subprocess-exited-with-error
error: command 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.35.32215\bin\HostX86\x64\cl.exe' failed with exit code 2
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
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
我有python 3.12和VS 2022。我已经下载了Microsoft c++ Build Tools for VS.
从注释来看,解决方案是从Python 3.12降级到Python 3.11。
在我写这篇文章的时候,Python 3.12还没有正式发布,只是作为预发布版(3.12.06 a6)。因此,pyodbc维护者很可能没有在Python 3.12中为pyodbc构建二进制轮。由于没有二进制轮,pyodbc的本机部分将不得不从源代码构建,这将需要C/c++编译器和构建工具。但是,在这种情况下,似乎在构建包时遇到了编译器错误,因此包安装失败。
确切的编译错误是什么,以及错误是在pyodbc还是Python 3.12中,我不能说。