I am setting up local workspace for my Django project with MySQL on a Macbook AIR with M2 chip. All config are migrated from my old Macbook Pro with core i7 using OSX Migration Assistant.
I am having problem trying to run server on my local, i.e. python manage.py runserver
. The err msg is:
File "/Users/.../.venv/lib/python3.10/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
File "/Users/.../.venv/lib/python3.10/site-packages/MySQLdb/__init__.py", line 24, in <module>
version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined
- MySQL server is set up on my local and works fine.
- I am able to use mysql to connect to my local MySQL server, i.e.
mysql -u root -p
mysqlclient
is installed, the version is2.1.1
- While importing
MySQLdb
directly using python console, it seems python is having difficulty usingdlopen
to open the "c compiled" (not sure how this is called exactly) file, or it opened but there was error? Error as:
Python 3.10.6 (v3.10.6:9c7b4bd164, Aug 1 2022, 17:13:48) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "/Users/.../.venv/lib/python3.10/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: dlopen(/Users/.../.venv/lib/python3.10/site-packages/MySQLdb/_mysql.cpython-310-darwin.so, 0x0002): symbol not found in flat namespace '_mysql_affected_rows'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/.../.venv/lib/python3.10/site-packages/MySQLdb/__init__.py", line 24, in <module>
version_info, _mysql.version_info, _mysql.__file__
NameError: name '_mysql' is not defined
- Tried uninstall and reinstall without using cache:
python -m pip download mysqlclient==2.1.1 --no-binary :all:
, no luck. - Tried upgrading mysqlclient (2.2.0.2 was installed), Django directly asking if mysqlclient is installed.
Thanks for advance!