Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python import MySQLdb on MacOS M1 doesn't work

I have Python 3.8.8, mysql and mysql-client installed. I also have installed both mysql-connector-python==8.0.26 & mysqlclient==2.1.0 library using pip.

But the line

python -c "import MySQLdb"

returns this error :

> Traceback (most recent call last):
  File "/Users/louisgabilly/anaconda3/envs/venv/lib/python3.8/site-packages/MySQLdb/__init__.py", line 18, in <module>
    from . import _mysql
ImportError: dlopen(/Users/louisgabilly/anaconda3/envs/venv/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-darwin.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Users/louisgabilly/anaconda3/envs/venv/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-darwin.so
  Expected in: flat namespace
 in /Users/louisgabilly/anaconda3/envs/venv/lib/python3.8/site-packages/MySQLdb/_mysql.cpython-38-darwin.so
>
>During handling of the above exception, another exception occurred:
>
>Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/louisgabilly/anaconda3/envs/venv/lib/python3.8/site-packages/MySQLdb/__init__.py", line 24, in <module>
    version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined

I believe this error is due to MacOS M1.

like image 866
Louis Avatar asked May 08 '26 11:05

Louis


1 Answers

A good discussion is in https://github.com/PyMySQL/mysqlclient/issues/496 and this problem arises that the architecture (ARM64 or Intel) of the Python is not consistent with the architecture of mysqlclient. So, check which python you are using (since you might use some python you are not intended) and the consistence between them

like image 107
htlbydgod Avatar answered May 11 '26 01:05

htlbydgod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!