How to fix ImportError: dlopen(): symbol not found in flat namespace '_mysql_affected_rows' on Mac M1
-1
votes
1
answer
2326
views
I am having an issue with running a script within a python virtual environment.
I have installed MySQL, MySQL client, Django, and everything using Homebrew since I am on a Mac M1 (Apple M1 Pro running Sonoma 14.4). When I double-check this using pip install, I always get a requirement satisfied message. Also, I have no issues starting up a database within MySQL and accessing this database.
I have seen some information that this is a version error, but uninstalling and re-installing MySQL with
arch arm64 brew install mysql
provides the same errors as above. I have also seen some information saying to install just the specific library that is missing, but I am not sure which one that is in this case.
This is the complete error I am getting:
Traceback (most recent call last):
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/db/backends/mysql/base.py", line 15, in
import MySQLdb as Database
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/MySQLdb/__init__.py", line 17, in
from . import _mysql
ImportError: dlopen(/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/MySQLdb/_mysql.cpython-312-darwin.so, 0x0002): symbol not found in flat namespace '_mysql_affected_rows'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/giuseppespartico/Desktop/jrc-folder/kcb-ds/./manage.py", line 21, in
main()
File "/Users/giuseppespartico/Desktop/jrc-folder/kcb-ds/./manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
utility.execute()
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/core/management/__init__.py", line 416, in execute
django.setup()
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/apps/registry.py", line 116, in populate
app_config.import_models()
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/apps/config.py", line 269, in import_models
self.models_module = import_module(models_module_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 1387, in _gcd_import
File "", line 1360, in _find_and_load
File "", line 1331, in _find_and_load_unlocked
File "", line 935, in _load_unlocked
File "", line 995, in exec_module
File "", line 488, in _call_with_frames_removed
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/contrib/auth/models.py", line 3, in
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/contrib/auth/base_user.py", line 57, in
class AbstractBaseUser(models.Model):
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/db/models/base.py", line 143, in __new__
new_class.add_to_class("_meta", Options(meta, app_label))
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/db/models/base.py", line 371, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/db/models/options.py", line 243, in contribute_to_class
self.db_table, connection.ops.max_name_length()
^^^^^^^^^^^^^^
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/db/utils.py", line 193, in create_connection
backend = load_backend(db["ENGINE"])
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/db/utils.py", line 113, in load_backend
return import_module("%s.base" % backend_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/giuseppespartico/Desktop/jrc-folder/biomonenv/lib/python3.12/site-packages/django/db/backends/mysql/base.py", line 17, in
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
Does anyone know how to fix this?
Asked by sparticat
(1 rep)
Apr 18, 2024, 01:22 PM
Last activity: May 18, 2024, 04:01 PM
Last activity: May 18, 2024, 04:01 PM