Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I am trying to install pyodbc in MacBook Pro M3 chip - arm64. The drivers are installed succesfully for odbc 13,17 and 18. But pyodbc is not able to detect the drivers. ERROR: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 17 for SQL Server' : file not found (0) (SQLDriverConnect)") #1346

Closed
Himanshup21234 opened this issue Apr 17, 2024 · 5 comments

Comments

@Himanshup21234
Copy link

Himanshup21234 commented Apr 17, 2024

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: 4.3.7
  • pyodbc: 4.0.30
  • OS: Mac M3 ARM64
  • DB: Azure SQL
  • driver: ODBC 17

Issue

I have Mac M3 Pro, trying to connect to Azure SQL server using pyodbc. my settings works well on my previous mac intel chip base laptop, but not here.
This is the error I get when trying to connect to sql server using pyodbc

Error: ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/homebrew/lib/libmsodbcsql.17.dylib' : file not found (0) (SQLDriverConnect)")

I checked lipo -info /opt/homebrew/Cellar/msodbcsql18/18.1.1.1/lib/libmsodbcsql.18.dylib

@Himanshup21234
Copy link
Author

Screenshot 2024-04-17 at 12 56 18 PM

@v-chojas
Copy link
Contributor

Are you using an arm64 or amd64 Python?
The issue form asks those questions for a reason, so fill it in.

@Himanshup21234
Copy link
Author

@v-chojas
ARM64 - I am using Apple M3 Pro.

@tatianass
Copy link

I used this tutorial to make it work on my M1 mac, maybe it can help you.

PS: Don't forgot to change the 18s to 17, since that's the driver version you want.

Tutorial

Following: microsoft/homebrew-mssql-release#53

  • Uninstall M1 versions of brew packages (if installed at all):
brew uninstall unixodbc msodbcsql18 mssql-tools18
  • Install x86 Homebrew alongside the ARM M1 homebrew:
arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  • Then use x86 homebrew like arch -x86_64 /usr/local/bin/brew install or use the following alias (add to ~/.bash_profile or ~/.zshrc):
# Relies on having installed x86 brew like:
# arch -x86_64 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
alias x86brew="arch -x86_64 /usr/local/bin/brew"
alias brew="/opt/homebrew/bin/brew"  # M1 version, to avoid from using x86 version accidentally
  • Install the ODBC packages.
x86brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
x86brew update
HOMEBREW_ACCEPT_EULA=Y x86brew install msodbcsql18 mssql-tools18
  • Create an x86 conda env with:
ENV_NAME="rosetta"
CONDA_SUBDIR=osx-64 conda create -n $ENV_NAME python
conda activate $ENV_NAME
conda config --env --set subdir osx-64
  • In order to install pyodbc, add to path (add to ~/.bash_profile or ~/.zshrc):
export LDFLAGS="-L/usr/local/Cellar/unixodbc/2.3.12/lib"
export CPPFLAGS="-I/usr/local/Cellar/unixodbc/2.3.12/include"
export PKG_CONFIG_PATH="/usr/local/Cellar/unixodbc/2.3.12/lib/pkgconfig"

PS: Pyodbc needs to be a recent version to be used with MAC M1.

@v-chojas
Copy link
Contributor

v-chojas commented May 3, 2024

That will work if you need to run x86 Python on an arm64 Mac for some reason, but beware that if you have other Python packages that are arm64, your x86 Python won't work with them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants