-
Notifications
You must be signed in to change notification settings - Fork 565
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
Cannot import pyodbc
with latest version on Apple Silicon
#1124
Comments
Many thanks for the feedback, @nleroy917 . Just as an experiment, could I ask you to try setting the LDFLAGS and CPPFLAGS environment variables before installing pyodbc, per the wiki? Many thanks. I appreciate pyodbc should "just install" but all feedback is useful. |
It doesn't appear that worked 😕 Steps:New python -m venv .venv
source .venv/bin/activate Find version of ls /opt/homebrew/Cellar/unixodbc/
2.3.11 Export flags: export LDFLAGS="-L/opt/homebrew/Cellar/unixodbc/2.3.11/lib"
export CPPFLAGS="-I/opt/homebrew/Cellar/unixodbc/2.3.11/include" Install, verify version: pip install pyodbc
pip freeze
pyodbc==4.0.35 Test: python
>>> import pyodbc
>>> (0x0002): symbol not found in flat namespace '_SQLAllocHandle' |
Hi @nleroy917! I've just had the same issue the other day. I managed to fix it with a
|
Ahh. Is this specifiable in a |
I would also like to upvote the issue because ver. 4.0.34 works fine without compiling from source.
|
FYI, pyodbc 4.0.34 didn't include wheel files for ARM64 MacOSX, only regular macs. https://pypi.org/project/pyodbc/4.0.34/#files Yes, on M1 macs, please use the |
Thanks for the help! I'll close this. |
@nleroy917 This is a genuine issue so let's keep this open for the time being. Other people will then be able to see it. Thank you pointing out this issue and also for your comprehensive notes (these are always greatly appreciated!). We will investigate and figure out what's going on. Meanwhile, I will update the Wiki with the workaround. |
I came here with the same problem but we're using
(or add the This configures poetry itself so won't stop other machines on the same project doing binary installs. |
Thank you for this. I came with the same issue and this fixed it. |
Note that in |
unable to install pip3 install --no-binary :all: pyodbc==4.0.34 getting following error src/pyodbc.h:45:10: fatal error: 'Python.h' file not found |
If the problem with the wheel is known, or wheel files can be compiled manually, would it be possible to re-issue a fixed wheel file for the m1 architecture with a higher build number/build-tag? This page discusses how one might do this: https://snarky.ca/what-to-do-when-you-botch-a-release-on-pypi/ |
Did you install python-dev or similar package that contains the headers (including Python.h)? |
Hi I tried this method but it's not working. Python: 3.10.5
does any one have any other idea? |
Do you have unixODBC (arm64 binary) installed? |
The fix worked for me just now. One difference I can see is that I have Python 3.11 installed. Also, since you have |
Would you be able to send a screenshot of what you get when running I found that I had to uninstall my initial installation of pyodbc before running the above command. |
@Emmanuel-Tsavaris thanks a lot, |
Managed to use the binary build globally - Python 3.10.9 Homebrew (pip3 install --no-binary :all: pyodbc). Then when creating my virtual environment I used: |
@anibal2j do you have unixodbc installed (brew install unixodbc)?
|
It seems I didn't have unixodbc installed, so I installed it with your homebrew instructions. Then I did pip install and that worked, but I'm using python3 so I ran pip3 install --no-binary :all: pyodbc and that fails: So, my script is still throwing: Anibals-New-MacBook-Air:FFI anibal$ python3 testmssql.py |
@anibal2j , a couple of things. Firstly, I'd definitely recommend using virtual environments when "pip installing", but I would also suggest not using Python either from homebrew or the built-in version on your Mac. You may want to consider using a utility like PYENV SETUP (optional) If you want to install Python with
In your ~/.bash_profile file, add the following:
Then, in a NEW shell, you can install multiple versions of Python like so:
(they get installed to directory ~/.pyenv/versions) To set the Python versions you would like available at the command line (in order of priority), use "pyenv global":
After running the above command, the commands "python3.10", "python3", and "python" all point to the Python 3.10.7 installation, and "python3.8" points to Python 3.8.12 (you can't choose the incremental version). VIRTUAL ENVIRONMENTS Even if you don't want to use
Try that and see if it works for you. |
Excellent!! Thanks a lot! I hadn't put the time to learn about this venv and now that I see how it works, it's great. I'll start using it going forward. I'm sticking with 3.9.16 for now. I followed all your commands and now I get this:
So, it looks good. But my test program, which is to open a connection to an MS SQL server still fails with this:
The script has this:
|
Thanks. Can you run the following to help me troubleshoot this: import platform
print(platform.processor()) |
UPDATE: Never mind - I see the previous post has the same error and does have unixodbc installed. @falkben Could your error indicate it is not finding the ODBC driver manager?
This function is not a pyodbc function but rather an ODBC function that should be implemented by the driver manager. Are you able to run pyodbc when builing from source? Do you have unixodbc installed? |
It is somehow related to either (1) not finding unixodbc or (2) an architecture mismatch. Running the Python snippet I supplied above will tell us if Python is running under Rosetta. Can you also run Does anyone have any other recommended ways to tell? I'm going by this: https://apple.stackexchange.com/a/416044 |
i've tried in a conda environment (with unixodbc installed into the conda environment) and a When installing with:
it is able to import pyodbc without error |
@falkben OK, thanks. I'm going to have to borrow my wife's M1 mac and work on this. |
Worked on Apple M1 Max |
By the way if anyone else is also having problems even with the workaround, make sure you uninstall the x86 unixodbc and Microsoft odbc installations if you happen to have a Rosetta installation of brew on the side. That was what caused my problem, once I removed those it worked. |
that's very advanced problem solving, I salut you sir. |
I thought we were just waiting for some Apple Silicon GitHub action runners for building, but now I seriously don't know if we can even have a good solution given that the environment on Mac varies so much due to Rosetta. Does anyone feel like they are sure what the solution really is and could spell it out in detail? Do we pick the "best", like all AS, and somehow detect and raise an error if the env doesn't match? |
Macbook Pro M1. I am able to successfully install and import pyodbc using conda by running. I am able able to install using pip, but fails upon import. If I run Any ideas why it works fine with conda but not pip? |
This is what worked for me: poetry install
# make sure this runs successfully
odbcinst -j
export LDFLAGS="-L$(brew --prefix unixodbc)/lib"
export CPPFLAGS="-I$(brew --prefix unixodbc)/include"
pip uninstall pyodbc
pip cache remove pyodbc
pip install --no-binary :all: pyodbc |
Any chance we can resolve this internally so M1 users don't need a special command/flag? We need our code to work across OSX, unix, Windows servers. Would prefer not to write conditional logic based on OS. Thanks! |
Uninstall pyodbc and reinstall with: |
Worked for me as well on macOS Sonoma with M1 Max |
hey. i work on mac m3 try all recomendation. i had an Error loading pyodbc module: dlopen(/Users/cheef/.local/share/virtualenvs/FAM-LuwvcngT/lib/python3.11/site-packages/pyodbc.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace '_SQLAllocHandle'. by the way for python 3.9 the same error. unixODBC 2.3.12 oh, and one more i use a pipenv. Can some one help me with that please?))) |
This was a very long road. I hope we're at the end. Version 5.1.0 has been released with both Intel and ARM binaries, so hopefully pip will do the right thing. We'd appreciate any feedback from Mac users. I'll keep this open for a while until we find out how well they will work. |
Just tested on Macbook M1, works as intended! Thank you for all the hard work that went into this. So glad its fixed! ❯ pip install pyodbc==5.1.0
Looking in indexes: https://pypi.org/simple
Collecting pyodbc==5.1.0
Obtaining dependency information for pyodbc==5.1.0 from https://files.pythonhosted.org/packages/a5/2f/32e8845205e7fc31f67d8b01c8906b964bfbf640aa6306aba8e696eeef79/pyodbc-5.1.0-cp311-cp311-macosx_11_0_arm64.whl.metadata
Using cached pyodbc-5.1.0-cp311-cp311-macosx_11_0_arm64.whl.metadata (2.7 kB)
Using cached pyodbc-5.1.0-cp311-cp311-macosx_11_0_arm64.whl (71 kB)
Installing collected packages: pyodbc
Successfully installed pyodbc-5.1.0
[notice] A new release of pip is available: 23.2.1 -> 24.0
[notice] To update, run: python3.11 -m pip install --upgrade pip
❯ python -c 'import pyodbc; print(pyodbc)'
<module 'pyodbc' from '/Users/jshaw/.pyenv/versions/datapipeline/lib/python3.11/site-packages/pyodbc.cpython-311-darwin.so'> |
Tested on a Macbook M2 ( |
on Mac M3 ok too. Thanks a lot. |
|
Hey. Are you made a copy of the system to your Mac m3 from your pervious Mac? Why i asking it, because I do and it copied also a homebrew. My previous Mac was on intel processor. That’s a problem. You need to uninstall howebrew, then install all from scratch. |
@igorvgalas No, I did not copy any settings from my old Mac. This is a new laptop setup. I freshly installed homebrew, yet i am facing the same issue. |
What error message do you get? |
The steps followed: Step1: Step2: Step3: Step4: output of odbcinst -j ImportError: dlopen(/Users/brindarao/.venv/lib/python3.9/site-packages/pyodbc.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_SQLAllocHandle' |
Try to install windows driver 17. |
I followed some variation of recommended steps 9 different ways. Couldn't figure out what was going on. I consistently got the Steps I kept followingbrew install unixodbc
# make sure this runs successfully
odbcinst -j
brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release
brew update
HOMEBREW_ACCEPT_EULA=Y brew install msodbcsql18 mssql-tools18
# check out installed drivers
cat /opt/homebrew/etc/odbcinst.ini
export LDFLAGS="-L$(brew --prefix unixodbc)/lib"
export CPPFLAGS="-I$(brew --prefix unixodbc)/include"
pip uninstall pyodbc
pip cache remove pyodbc
pip install --no-binary :all: pyodbc x86 Python vs ARM PythonFinally I noticed that wheel in my What I did not realize is that there are ARM versions of Python and x86 versions of python, and x86 versions can work from ARM terminals. I confirmed this by running python -c "import platform; print(platform.processor())"
> i386 So the problem was that my Homebrew was in ARM world, and my Python was in x86 world. I assume that I could have fixed the problem by installing an ARM version of Python. However, I simply installed an x86 version of |
Yes, you need to have either consistently arm64 or amd64 software. Python needs to match pyODBC which then needs to match unixODBC and the ODBC driver(s) you need to use. |
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:
3.10.6
4.0.35
Issue
overview:
I upgraded my
pyodbc
version to the latest on PyPi (v4.0.35
) and noticed I was getting a new error that I had never dealt with before. Specifically, when importingpyodbc
I receive the following:An issue for this was raised and closed a while ago; it references this exact problem: #885
expected behavior:
pyodbc
should import without issuesteps to reproduce:
pyodbc
:pip install pyodbc
pyodbc
and observe error:The text was updated successfully, but these errors were encountered: