Reputation: 71
I am trying to install pyodbc with pip on macOS(12.3.1), but that didn't work.
In error log, Message says "fatal error: 'sql.h' file not found". Some people are helped by the command brew install unixodbc
. I did run brew install unixodbc
, but errors remain emerge.
My environment: Macbook pro M1 pip (22.0.4) Python (3.10) pyenv (2.2.5)
I'm sorry for broken english and poor understand on python.
% pip3 install pyodbc
Collecting pyodbc
Using cached pyodbc-4.0.32.tar.gz (280 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: pyodbc
Building wheel for pyodbc (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [14 lines of output]
running bdist_wheel
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.macosx-12.1-arm64-3.10
creating build/temp.macosx-12.1-arm64-3.10/src
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
In file included from src/buffer.cpp:12:
src/pyodbc.h:56:10: fatal error: 'sql.h' file not found
#include <sql.h>
^~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for pyodbc
Running setup.py clean for pyodbc
Failed to build pyodbc
Installing collected packages: pyodbc
Running setup.py install for pyodbc ... error
error: subprocess-exited-with-error
× Running setup.py install for pyodbc did not run successfully.
│ exit code: 1
╰─> [14 lines of output]
running install
running build
running build_ext
building 'pyodbc' extension
creating build
creating build/temp.macosx-12.1-arm64-3.10
creating build/temp.macosx-12.1-arm64-3.10/src
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
In file included from src/buffer.cpp:12:
src/pyodbc.h:56:10: fatal error: 'sql.h' file not found
#include <sql.h>
^~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> pyodbc
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
Upvotes: 6
Views: 6464
Reputation: 7506
brew install unixodbc
export LDFLAGS="-L/opt/homebrew/Cellar/unixodbc/[your version]/lib"
export CPPFLAGS="-I/opt/homebrew/Cellar/unixodbc/[your version]/include"
pip install pyodbc
pyodbc
doesn't have pre-build wheels for M1 mac. See https://pypi.org/project/pyodbc/#files . If I remember correctly, pre-build wheels for M1 should have tag looks like pandas-1.4.3-cp38-cp38-macosx_10_9_universal2.whl
, "universal".
So what pip does is downloading the source (tar.gz
) and trying to build locally. Then you need some C header files and source files to in order to bulid.
brew install unixodbc
install those files. But for brew
installed on M1 mac, those files are not installed in system default search directories. So that's why you need to manually speicify some additional directories for the compiler to search and then run pip install pyodbc
:
export LDFLAGS="-L/opt/homebrew/Cellar/unixodbc/[your version]/lib"
export CPPFLAGS="-I/opt/homebrew/Cellar/unixodbc/[your version]/include"
related issue: https://github.com/mkleehammer/pyodbc/issues/988
Upvotes: 17
Reputation: 71
I encountered the problem when trying to install pyodbc==4.0.31 but performing an update to pyodbc==4.0.34 solved my problem.
Upvotes: 4