Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to import pyodbc on Apple Silicon - Symbol not found: _SQLAllocHandle

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?

like image 947
eckha Avatar asked Nov 18 '25 11:11

eckha


1 Answers

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
like image 50
zhrist Avatar answered Nov 21 '25 02:11

zhrist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!