I migrated my data to M1 Monterey MacOS from intel macmini. I was happy to use django and mariadb until I installed a package using homebrew. I installed homebrew and installed vim with it, and then my django-mariadb connection suddenly stopped working.
I found out that the error was caused in python3.7/site-packages/MySQLdb/init.py in 18th line in my venv.
try:
from MySQLdb.release import version_info
from . import _mysql # this line causes the problem
assert version_info == _mysql.version_info
except Exception:
raise ImportError(
"this is MySQLdb version {}, but _mysql is version {!r}\n_mysql: {!r}".format(
version_info, _mysql.version_info, _mysql.__file__
)
)
And the stacktrace goes
Traceback (most recent call last):
File "/Users/gwanghyeongim/Documents/revhat/basecamp/.venv/basecamp/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: dlopen(/Users/gwanghyeongim/Documents/revhat/basecamp/.venv/basecamp/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 0x0002): Library not loaded: /usr/local/opt/mariadb/lib/libmariadb.3.dylib
Referenced from: /Users/gwanghyeongim/Documents/revhat/basecamp/.venv/basecamp/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
Reason: tried: '/usr/local/opt/mariadb/lib/libmariadb.3.dylib' (no such file), '/usr/lib/libmariadb.3.dylib' (no such file)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/gwanghyeongim/Documents/revhat/basecamp/.venv/basecamp/lib/python3.7/site-packages/MySQLdb/__init__.py", line 24, in <module>
version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined
I had written a post about '_mysql not defined' some time ago, and I fixed the problem by exporting a path in my ~/.zshrc
. But this time I googled the mysterious file libmariadb.3.dylib
, but couldn't find satisfying results: most posts were about libmysqlclient.21.dylib
.
I suspect this is due to homebrew on M1. As if to confirm my suspicion, there are some issues on mysqlclient github, and a notable one addresses similar problem, but the maintainer doesn't seem so much passionate in helping.
I installed and reinstalled brew, and even tried installing Rosetta2 homebrew following this page, with no avail.
Another homebrew issue page unfortunately didn't help me much either.
My environment are as follows:
- python3.7.7 installed through installer
- Apple M1 pro Monterey Version 12.0.01
- mysqlclient 2.1.0
Any help or thoughts please?