11

I am currently working on a python (3.8) project on my 2021 MacBook Pro with Apple Silicon. Ultimately, the goal is to build a ML model on data I read from an Azure SQL DB using Apple's Tensorflow fork. Therefore, I am developing the project on native Apple Silicon packages - not using Rosetta.

The Problem arises when I try to import the pyodbc package (4.0.30) in order to connect to my DB. I keep getting the following error

  File "<stdin>", line 1, in <module>
ImportError: dlopen({myvenv}/lib/python3.8/site-packages/pyodbc.cpython-38-darwin.so, 2):
Symbol not found: _SQLAllocHandle
  Referenced from: {myvenv}/lib/python3.8/site-packages/pyodbc.cpython-38-darwin.so
  Expected in: flat namespace
 in {myvenv}/lib/python3.8/site-packages/pyodbc.cpython-38-darwin.so

If however, I do the exact same thing using Rosetta everything works fine. I couldn't find any other thread describing a similar behaviour.

Does anyone know how to resolve this issue?

eckha
  • 113
  • 1
  • 5
  • When you installed pyodbc did pip use the pre-compiled wheel (.whl) file? – Gord Thompson Mar 21 '21 at 13:17
  • pip built from source as there is no wheel available yet for apple silicon unfortunately. Is there anything to consider when building pyodbc from source? – eckha Mar 21 '21 at 14:43
  • Well, on Mac there's at least the whole iODBC/unixODBC thing so you may want to raise an [issue on GitHub](https://github.com/mkleehammer/pyodbc/issues) to see if any of the developers might have an idea. – Gord Thompson Mar 21 '21 at 16:46
  • Did you ever manage to fix this? – jtlz2 Sep 12 '22 at 13:59

2 Answers2

19

My feeling is that the package is not compiled properly for ARM architecture.

You can uninstall the pyodbc and install it again. If using pip, it would be like this:

pip uninstall pyodbc

and install with compiling it locally:

pip install --no-binary :all: pyodbc

Do not forget on Unix/Linux like platforms, you need to download the unixodbc source distribution, as pyodbc is build against an ODBC driver manager, i.e. unixodbc is a prerequisite. Example installation with brew package manager:

brew install unixodbc
zhrist
  • 1,169
  • 11
  • 28
2

The not-compiled installation should work:

pip install --pre --no-binary :all: pyodbc

This compiles locally and is thus compatible and overcomes the issue.

zhrist
  • 1,169
  • 11
  • 28