対応方法 When using MySQLdb with Python and encountering "symbol not found in flat namespace '_mysql_affected_rows'"
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
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.