Unable to import pyodbc on Apple Silicon – Symbol not found: _SQLAllocHandle
Question:
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?
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
The not-compiled installation should work:
pip install --pre --no-binary :all: pyodbc
This compiles locally and is thus compatible and overcomes the issue.
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?
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
The not-compiled installation should work:
pip install --pre --no-binary :all: pyodbc
This compiles locally and is thus compatible and overcomes the issue.