対応方法 When using MySQLdb with Python and encountering "symbol not found in flat namespace '_mysql_affected_rows'"

Django Python
2023-11-09 12:39 (1 years ago) ytyng

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.

Currently unrated

Comments

Archive

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011