我尝试在 macOS(12.3.1) 上使用 pip 安装 pyodbc,但这不起作用。
\n在错误日志中,消息显示“致命错误:找不到'sql.h'文件”。有些人得到了命令的帮助brew install unixodbc。我确实跑了brew install unixodbc,但错误仍然出现。
我的环境:\nMacbook pro M1\npip (22.0.4)\nPython (3.10)\npyenv (2.2.5)
\n我很抱歉英语蹩脚,对 python 的理解也很差。
\n% pip3 install pyodbc \n\nCollecting pyodbc\n Using cached pyodbc-4.0.32.tar.gz (280 kB)\n Preparing metadata (setup.py) ... done\nBuilding wheels for collected packages: pyodbc\n Building wheel for pyodbc (setup.py) ... error\n error: subprocess-exited-with-error\n \n \xc3\x97 python setup.py bdist_wheel did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [14 lines of output]\n running bdist_wheel\n running build\n running build_ext\n building 'pyodbc' extension\n creating build\n creating build/temp.macosx-12.1-arm64-3.10\n creating build/temp.macosx-12.1-arm64-3.10/src\n clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -DPYODBC_VERSION=4.0.32 -UMAC_OS_X_VERSION_10_7 -I/usr/local/include -I/Users/daiki/.pyenv/versions/3.10.0/include/python3.10 -c src/buffer.cpp -o build/temp.macosx-12.1-arm64-3.10/src/buffer.o -Wno-write-strings -Wno-deprecated-declarations\n In file included from src/buffer.cpp:12:\n src/pyodbc.h:56:10: fatal error: 'sql.h' file not found\n #include <sql.h>\n ^~~~~~~\n 1 error generated.\n error: command '/usr/bin/clang' failed with exit code 1\n [end of output]\n \n note: This error originates from a subprocess, and is likely not a problem with pip.\n ERROR: Failed building wheel for pyodbc\n Running setup.py clean for pyodbc\nFailed to build pyodbc\nInstalling collected packages: pyodbc\n Running setup.py install for pyodbc ... error\n error: subprocess-exited-with-error\n \n \xc3\x97 Running setup.py install for pyodbc did not run successfully.\n \xe2\x94\x82 exit code: 1\n \xe2\x95\xb0\xe2\x94\x80> [14 lines of output]\n running install\n running build\n running build_ext\n building 'pyodbc' extension\n creating build\n creating build/temp.macosx-12.1-arm64-3.10\n creating build/temp.macosx-12.1-arm64-3.10/src\n clang -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -DPYODBC_VERSION=4.0.32 -UMAC_OS_X_VERSION_10_7 -I/usr/local/include -I/Users/daiki/.pyenv/versions/3.10.0/include/python3.10 -c src/buffer.cpp -o build/temp.macosx-12.1-arm64-3.10/src/buffer.o -Wno-write-strings -Wno-deprecated-declarations\n In file included from src/buffer.cpp:12:\n src/pyodbc.h:56:10: fatal error: 'sql.h' file not found\n #include <sql.h>\n ^~~~~~~\n 1 error generated.\n error: command '/usr/bin/clang' failed with exit code 1\n [end of output]\n \n note: This error originates from a subprocess, and is likely not a problem with pip.\nerror: legacy-install-failure\n\n\xc3\x97 Encountered error while trying to install package.\n\xe2\x95\xb0\xe2\x94\x80> pyodbc\n\nnote: This is an issue with the package mentioned above, not pip.\nhint: See above for output from the failure.\nRun Code Online (Sandbox Code Playgroud)\n
Ric*_*ick 17
brew install unixodbc
Run Code Online (Sandbox Code Playgroud)
export LDFLAGS="-L/opt/homebrew/Cellar/unixodbc/[your version]/lib"
export CPPFLAGS="-I/opt/homebrew/Cellar/unixodbc/[your version]/include"
Run Code Online (Sandbox Code Playgroud)
pip install pyodbc
Run Code Online (Sandbox Code Playgroud)
pyodbc没有适用于 M1 mac 的预制轮子。请参阅https://pypi.org/project/pyodbc/#files。如果我没记错的话,M1 的预制轮子应该有类似pandas-1.4.3-cp38-cp38-macosx_10_9_universal2.whl“通用”的标签”的标签。
所以 pip 所做的就是下载源代码 ( tar.gz) 并尝试在本地构建。然后你需要一些 C 头文件和源文件才能构建。
brew install unixodbc安装这些文件。但对于brew安装在 M1 mac 上,这些文件不会安装在系统默认搜索目录中。因此,这就是为什么您需要手动指定一些附加目录供编译器搜索然后运行pip install pyodbc:
export LDFLAGS="-L/opt/homebrew/Cellar/unixodbc/[your version]/lib"
export CPPFLAGS="-I/opt/homebrew/Cellar/unixodbc/[your version]/include"
Run Code Online (Sandbox Code Playgroud)
相关问题: https: //github.com/mkleehammer/pyodbc/issues/988