pyodbc icon indicating copy to clipboard operation
pyodbc copied to clipboard

Failed to build pyodbc. Cannot install on M1 MAC Monterey

Open MiguelElGallo opened this issue 2 years ago • 8 comments

Please first make sure you have looked at:

  • Documentation: https://github.com/mkleehammer/pyodbc/wiki
  • Other issues

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be sure to specify 32-bit Python or 64-bit:

  • Python: Python 3.8.9
  • pyodbc:
  • OS: Monterrey 12.0.1 (21A559)
  • DB: MSSQL
  • driver: 17.8

Issue

When installing PyODBC it fails with: 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

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 'clang' failed with exit status 1

ERROR: Failed building wheel for pyodbc

MiguelElGallo avatar Dec 08 '21 13:12 MiguelElGallo

Please install unixODBC first ,as pointed out in the documentation.

v-chojas avatar Dec 08 '21 15:12 v-chojas

Is installed and working: unixodbc 2.3.9_1 , error still persists

MiguelElGallo avatar Dec 08 '21 17:12 MiguelElGallo

Is the file sql.h in /usr/local/include/ or /usr/local/Cellar/unixodbc/2.3.9/include/ (if it was installed via brew)? I believe that's where it should be placed after installing unixODBC. If the files are there then there is something wrong with installation not looking in the right paths.

v-makouz avatar Dec 14 '21 23:12 v-makouz

Installing unixodbc and Setting LDFLAGS and CPPFLAGS as mentioned on the main issue (https://github.com/mkleehammer/pyodbc/issues/846#issuecomment-986649632) for this worked for me.
My path was slightly different. Check yours.

ll /opt/homebrew/Cellar/unixodbc

askpatrickw avatar Dec 14 '21 23:12 askpatrickw

@MiguelElGallo See https://github.com/mkleehammer/pyodbc/issues/846#issuecomment-813255685 for a workaround.

The default Homebrew installation path has changed for M1 Macs: /usr/local/ --> /opt/homebrew/.

PSalant726 avatar Dec 15 '21 00:12 PSalant726

If your python is running under x86_64 architecture, install unixodbc using x86_64 version of homebrew, which will stay in same location /usr/local/Homebrew/bin/brew.

It seems that pyodbc is not supported for arm64 yet, so installing everything in x86_64 architecture works for me.

PWbio avatar Dec 28 '21 03:12 PWbio

Is the file sql.h in /usr/local/include/ or /usr/local/Cellar/unixodbc/2.3.9/include/ (if it was installed via brew)? I believe that's where it should be placed after installing unixODBC. If the files are there then there is something wrong with installation not looking in the right paths.

This was the problem for me, after applying those two steps problem solved..

Bturan19 avatar Mar 31 '22 10:03 Bturan19

After looking around this is the solution that worked for me:

Step 1 - Install unixodbc with brew brew install unixodbc

Step 2 - Make sure to note the version that has just been installed (as of today, I installed unixodbc 2.3.11)

Step 3 - Create the links just like in the documentation that you provided https://github.com/mkleehammer/pyodbc/wiki export LDFLAGS="-L/opt/homebrew/Cellar/unixodbc/[your version]/lib" export CPPFLAGS="-I/opt/homebrew/Cellar/unixodbc/[your version]/include"

Step 4 - Go on your project to install pyodbc pip install pyobdc

And watch it FINALLY work!!

Lilya-CB avatar Jul 06 '22 17:07 Lilya-CB

Earlier releases did not include Apple Silicon / ARM binary wheels, but we've added them to 5.0.0 beta 2. If you can, please test them. Details here:

https://github.com/mkleehammer/pyodbc/discussions/1263

mkleehammer avatar Aug 28 '23 21:08 mkleehammer

Below command worked for to get wheel python -m pip install --only-binary=:all: pyodbc==4.0.32

But how to install ODBC driver in AWS Glue to connect AWS Microsoft RDS ?

ramyaelineni5 avatar Dec 05 '23 04:12 ramyaelineni5

Fixed by #1323 .

keitherskine avatar Feb 06 '24 00:02 keitherskine