Fix: symbol not found in flat namespace '_mysql_affected_rows' when importing MySQLdb on Apple Silicon
DjangoPython
2023-11-09 03:39 (2 years ago)
Attempted to operate MySQL using Python on Apple Silicon, but encountered the following error:
ImportError: dlopen(/.../site-packages/MySQLdb/_mysql.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_mysql_affected_rows'
Referring to the comment in the following link:
Macos M1 mysqlclient Symbol not found: _mysql_affected_rows ERROR · Issue #496 · PyMySQL/mysqlclient
In my environment, the output was:
% echo $MYSQLCLIENT_LDFLAGS
-L/opt/homebrew/opt/openssl/lib -L/opt/homebrew/opt/mysql/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/lib
So, I modified it to:
% echo $MYSQLCLIENT_LDFLAGS
-L/opt/homebrew/opt/openssl/lib -L/opt/homebrew/opt/mysql/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/lib -lmysqlclient -rpath /opt/homebrew/opt/mysql/lib
After that, I executed the following commands:
pip uninstall mysqlclient
pip cache purge
pip install mysqlclient
If there are no errors when executing:
python3
>>> import MySQLdb
>>>
then it's OK.
Please rate this article (No signup or login required)
Currently unrated
Related posts
[Outdated] Using Selenium Remote (Selenium Grid) with browser_use
Obtain HttpOnly=True Session Cookies from Services Logged in via Browser-Use
Fix: Python 3.13 SSL error 'Basic Constraints of CA cert not marked critical' (VERIFY_X509_STRICT)
How to Fix Display Issues in Django Admin Inlines After Upgrading to 5.1
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.