-
Notifications
You must be signed in to change notification settings - Fork 435
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
Macos M1 mysqlclient Symbol not found: _mysql_affected_rows ERROR #496
Comments
I'm struggling with a proper solution too. MYSQLCLIENT_CFLAGS="-I/opt/homebrew/opt/mysql@5.7/include/mysql" MYSQLCLIENT_LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib" pip install -I mysqlclient That said, above still doesn't produce a working module on my m1 mac-- even though install seems to succeed. It still borks on lines like If you really have to get this working now, you can use this:, however despite the claims there, |
dug in a bit more: no matter how I install sudo symbols [path to your packages]/MySQLdb/_mysql.cpython-36m-darwin.so -arch x86_64 | grep mysql_affected_rows
0x00000000000071bc ( 0x6) DYLD-STUB$$mysql_affected_rows [DYLD-STUB, LENGTH, NameNList, MangledNameNList, NList] However, the actual mysqlclient dlyld is for arm64. Maybe this is part of the problem. For example: sudo symbols /opt/homebrew/Cellar/mysql@5.7/5.7.34/lib/libmysqlclient.dylib -arch arm64 | grep affected_rows
Password:
0x00000000000067e0 ( 0x8) mysql_affected_rows [FUNC, EXT, NameNList, MangledNameNList, Merged, NList, FunctionStarts]
0x0000000000007af4 ( 0x8) mysql_stmt_affected_rows [FUNC, EXT, NameNList, MangledNameNList, Merged, NList, FunctionStarts] Seems like the bug is that pip install is not respecting either the current arch, or an arch flag given ( update: yes, pip install complains... |
ok-- I think this issue should be closed-- as I don't think there's a good solution and it is not an issue with this module. Python 3.X, X<9 on an M1 today is for x86_64 (intel) not arm64. The mysqlclient dyld is now native arm64, even for old sql like 5.7. Hence, when intel python calls |
@jcbloch could you show how you did this?
|
[I think this is what I did] I installed homebrew in a different location just for x86, something like this: mkdir homebrew-x86 && curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew-x86 Then the libs for 5.7 (but should work for other versions too) arch -x86_64 homebrew-x86/bin/brew install mysql-client@5.7 Which seemed to install the right things; eg: sudo symbols ~/homebrew-x86/Cellar/mysql-client@5.7/5.7.32/lib/libmysqlclient.dylib -arch x86_64 | grep mysql_affected_rows finally do the pip install (replace the MYSQLCLIENT_CFLAGS="-I/.../homebrew-x86/Cellar/mysql-client@5.7/5.7.32/include/mysql" MYSQLCLIENT_LDFLAGS="-L/.../homebrew-x86/Cellar/mysql-client@5.7/5.7.32/lib -lmysqlclient" arch -x86_64 pip install -I -vvv mysqlclient |
Hi, from MySQLdb import version
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/usr/local/Caskroom/miniconda/base/envs/twoex/lib/python3.7/site-packages/MySQLdb/__init__.py in <module>
17 from MySQLdb.release import version_info
---> 18 from . import _mysql
19
ImportError: dlopen(/usr/local/Caskroom/miniconda/base/envs/twoex/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 0x0002): symbol not found in flat namespace '_mysql_affected_rows' sudo symbols /usr/local/Caskroom/miniconda/base/envs/twoex/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so -arch x86_64 | grep mysql_affected_rows
0x00000000000071bc ( 0x6) DYLD-STUB$$mysql_affected_rows [DYLD-STUB, LENGTH, NameNList, MangledNameNList, NList] sudo symbols /usr/local/Cellar/mysql@5.7/5.7.36/lib/libmysqlclient.dylib -arch x86_64 | grep mysql_affected_rows
0x0000000000005887 ( 0xd) mysql_affected_rows [FUNC, EXT, NameNList, MangledNameNList, Merged, NList, FunctionStarts] |
Thanks @jcbloch This is what I did:
|
I also found out different shell give out different arch results. For the same file I use the ide-terminal to build all python, virtualenv, and mysqlclint, then it will work. If I install the python from the zch, it won't work. -- labii.com |
wonder why python mysqlclient installs ( _mysql.cpython-38-darwin.so ) x86_64 version instead of ARM64. |
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/MySQLdb/init.py", line 18, in During handling of the above exception, another exception occurred: Traceback (most recent call last): Getting above error with mysqlclient in my django application can anyone help |
In my django(2.2.6) app,i meet this question too. |
I got the same question and finally resolve it by homebrew(x86_64)、python(3.7.6 x86_64)、mysql@5.7(by x86_64 homebrew) and brew link/unlink[for me this is the important point]. My installation process is:
then i found pyenv cannot build python 3.7.6(which is my project need), so i install homebrew(x86_64) and use it by alias
I also edit my .zshrc file
Install Python 3.7.6(x86_64) as follow instruction:
Warning when install mysql-client[the important point]
Error when import MySQLdb:
I check the architecture for python and _mysql.cpython-37m-darwin.so, all of them are x86_64 Python:
_mysql.cpython-37m-darwin.so
so that must be my mysql wrong
add mysql@5.7(install by x86_64 homebrew) to .zshrc
After struggling on same ImportError result, finally I think that may be my brew link affect. So I run the following:
It works! I run my project as expected. |
Use Rosetta homebrew instead of native homebrew. This seems to cause the beginnig of nightmare. The following only applys to those who use M1 chip
When you type
Now your brew is rosetta homebrew, instead of native homebrew.
Now try importing MySQLdb in shell. It shouldn't log any stacktrace this time.
|
EDIT |
It's been a while, but I hope this comment will help someone. In my case, M1 was an arm64 architecture. So I installed the package from the system terminal, not from the Pycharm terminal. Actually, I checked with the |
I'am having the same issue still even after following the suggested instructions. Can someone please help in providing the step step instructions. |
For me the following worked. I had a previous installation of x86_64 brew and removed mysql from it. Since I have both homebrew versions, I created an alias for the x86_64 in Using the method below, all mysql stuff are m1/arm64 native: With m1 homebrew I did the following: Then with python (assuming you have python installed through homebrew, but I guess should work with conda as well?): |
Thank you so much. It worked now with the following steps. |
I think I missed installing mysql part with homebrew. Thanks for claryfing that @paulmadejong. |
in summary, I think this problem is caused by one problem: the pip installed mysqlclient lib (_mysql.cpython-38-darwin.so) arch doesn't match the brew installed mysql libs(eg. homebrew/Cellar/mysql/8.0.29/lib/libmysqlclient.21.dylib). And the mysqlclient lib's arch is same with your python's arch, and brew installed mysql lib always arm64 if your python is x86 arch, the problem occures: two way to solve:
|
I solved this problem by uninstalling all of my python in my M1 (since there are a lot of python versions and Anaconda versions) as well as update the ~/.bash_profile and ~/.zshrc to delete the export python pathes. Then I install native arm64 python version by |
It worked!!! |
I don't think the comments here get to the root of the issue. When building on OS X (Ventura in my case) the resulting library isn't linked against libmysqlclient, and this is why it can't find the symbol I don't know why that is the case, but I've worked around it using:
If you have a brew install of mysqlclient, you'll have to adjust the paths accordingly. With above I have a working version running natively in arm64 Python (I'm running on an M2 chip). |
Similarly, but here is another approach that may give you more clarity about the issue.Run this command to create brew_x86_64:
In .zshrc, temporarily switch brew to brew_x86_64:
Reload
Then retry the pip install with temporary brew_x86_64:
Then it worked:
|
Hello
I'm trying to install mysqlclient with this command pip install mysqlclient
but i'm having this errors
mysql : 8.0.2
python : 3.7.10
Mac: OS version: 11.2.3 M1
ImportError: dlopen(/Users/shiwei/insight_r2_backend/env3/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Symbol not found: _mysql_affected_rows
Referenced from: /Users/shiwei/insight_r2_backend/env3/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
Expected in: flat namespace
I set
LD_LIBRARY_PATH=/opt/homebrew/lib
The text was updated successfully, but these errors were encountered: