5

On macOS 12 pip install pyodbc results in error:

src/pyodbc.h:56:10: fatal error: 'sql.h' file not found

For older versions of macOS and Pip, this topic has been addressed in Installing pyodbc fails on OSX 10.9 (Mavericks). None of the provided answers there are not working with current versions.

1 Answer 1

6

Note: Reasons for failure seem to vary a lot over time given version of macOS, Pip, Homebrew, and unixODBC.

Running pip install pyodbc while specifying the location of unixODBC library works in pyodbc 4.0.32:

CPPFLAGS='-I/opt/homebrew/Cellar/unixodbc/2.3.9_1/include' \
  LDFLAGS='-L/opt/homebrew/Cellar/unixodbc/2.3.9_1/lib' \
  pip install pyodbc

There seems not to be need to install iODBC as unixODBC works.

Additionally, getting ODBC Driver for SQL Server is as tangled. Documentation at https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos isn't accurate as OpenSSL version 3 and 1 fails to correctly detect at install time.

Because of OpenSSL version conflict, connection attempts to SQL server will result in errors like:

  • SSL Provider: [OpenSSL library could not be loaded, make sure OpenSSL 1.0 or 1.1 is installed].
  • Client unable to establish the connection.
  • WARNING: <command/library here> is loading libcrypto in an unsafe way (followed by a process crash)

Various attempts to fix driver loading are described in https://github.com/microsoft/homebrew-mssql-release/issues/59.

Manually symlinking OpenSSL 1.1 fixes the problem at the time of writing:

ln -s /opt/homebrew/opt/[email protected]/lib/libssl.dylib /usr/local/lib/
ln -s /opt/homebrew/opt/[email protected]/lib/libcrypto.dylib /usr/local/lib/

Please understand, this is subject to change.

2
  • doesn't work for me Commented Jun 16, 2022 at 18:59
  • Please, provide any details on how your install fails. Commented Jun 16, 2022 at 20:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.