Yes, I had the same problem when I tried to do pip install mysqlclient on my MacBook Pro 2021 running Monterey 12.0.1 with an Apple Silicon M1 chip. I used a solution by Github user jcbloch found in the discussion in the link https://github.com/PyMySQL/mysqlclient/issues/496 which I found after
reading the https://github.com/PyMySQL/mysqlclient/issues/497 link that I found in sathira lamal's answer. The problem, as I learned from reading jcbloch's explanation, is with the Python that currently comes with the MacBook Pro
2021 with Monterey 12.0.1. That Python is built for x86_64 architecture. The mysqlclient library however has an arm64 version available, which is what you are going to get by default if you do something like brew install mysql-client . Using the file command shows the issue: $ file /Library/Frameworks/Python.framework/Versions/2.7/bin/python
/Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O 64-bit executable x86_64
The text above shows that python is x86_64 . $ file /opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib
/opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib: Mach-O 64-bit dynamically linked shared library arm64
The text above shows that libmysqlclient.21.dylib is $ file /opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib
/opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib: Mach-O 64-bit dynamically linked shared library arm64
0.To work around this, Github user
jcbloch created an alternative Homebrew installation that is set to use x86_64 architecture, used it to install an x86_64 version of the MySQL client library, then used that library when installing the MySQL client into Python via $ file /opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib
/opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib: Mach-O 64-bit dynamically linked shared library arm64
1.Here is what I had to do, which is basically the same thing jcbloch suggests. What differs is that I made sure to include an uninstall of any borked mysqlclient
python package and to drop all the cached pip libraries so that you don't just end up reinstalling the cached incorrect package again. And, I ended up with a slightly later version of MySQL client than jcbloch did. And, I had to include an $ file /opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib
/opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib: Mach-O 64-bit dynamically linked shared library arm64
2 variable to point to the x86_64 openssl library.Make sure to double check all the paths below before executing these commands. I got derailed for many hours because I had copied and pasted the wrong version of the mysql library in my last
command. cd /opt
mkdir homebrew-x86
curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew-x86
arch -x86_64 homebrew-x86/bin/brew install
rm -rf ~/Library/Caches/pip
pip uninstall mysqlclient
export PATH="/opt/homebrew-x86/opt//bin:$PATH"
CPPFLAGS="-I/opt/homebrew-x86/opt//include" LDFLAGS="-L/opt/homebrew-x86/opt//lib" MYSQLCLIENT_CFLAGS="-I/opt/homebrew-x86/Cellar//5.7.32/include/mysql" MYSQLCLIENT_LDFLAGS="-L/opt/homebrew-x86/Cellar//5.7.32/lib -lmysqlclient" arch -x86_64 pip install -I -vvv mysqlclient
And then, again as jcbloch suggests, I verified the installation by checking that the $ file /opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib
/opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib: Mach-O 64-bit dynamically linked shared library arm64
3 symbol is present. I guess that symbol only exists in the x86_64 architecture version of the MySQL client.$ sudo symbols homebrew-x86/Cellar//5.7.34/lib/libmysqlclient.dylib -arch x86_64 | grep mysql_affected_rows
0x0000000000003fe7 ( 0xd) mysql_affected_rows [FUNC, EXT, NameNList, MangledNameNList, Merged, NList, FunctionStarts]
Có ai tìm thấy giải pháp không? Tôi đang vật lộn với vấn đề này, tôi đã cài đặt M1 Python 3.9 bản địa, dự án hoạt động hoàn hảo với SQLite nhưng khi tôi chuyển cơ sở dữ liệu sang MySQL mặc dù tôi đã tải xuống MySQL Client, tôi nhận được lỗi dưới đây (Venv) (cơ sở) % python3 Management.py Makemigrations Traceback (cuộc gọi gần đây nhất cuối cùng): file "/người/salishkumar/backend/tiffinwala/venv/lib/python3.9 Nhập _MysQL ItrongRor: dlopen (/sers/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/mysqldb/_mysql.cpython-39-darwin.so, 0x000 ' I have installed native m1 python 3.9, project working perfectly with sqlite but when I switch database to mysql although I have downloaded mysql client I get below error (venv) (base) salishkumar@Salishs-MacBook-Pro tiffinwala % python3 manage.py makemigrations
Traceback (most recent call last): File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/MySQLdb/init.py", line 18, in from . import _mysql ImportError: dlopen(/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/MySQLdb/_mysql.cpython-39-darwin.so, 0x0002): symbol not found in flat namespace '_mysql_affected_rows' Trong quá trình xử lý ngoại lệ ở trên, một ngoại lệ khác đã xảy ra: Traceback (cuộc gọi gần đây nhất cuối cùng): file "/người sử dụng Trong tệp thực thi chính_from_command_line (sys.argv) tệp "/người/người/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages () Tệp "/người sử dụng /SalishKumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/init.py ", dòng 24, trong appup apps.population (settings.installed_apps) VenV/lib/python3.9/trang web trang web/django/apps/registry.py ", dòng 114, trong tập tin dân cư app_config.import_models () trang web-packages/django/apps/config.py ", dòng 300, trong intert_models self.models_module = intert_module (mo dels_module_name) Tệp "/người sử dụng/salishkumar/co dòng 1030, trong tệp _gcd_import "", dòng 1007, trong tệp _find_and_load "", dòng 986, trong tệp _find_and_load_unlocked "", dòng 680, trong tệp _load_unlocked "" Tệp "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages Tệp "/Users /SalishKumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/db/models/base.py ", dòng 122, trong new_class.add_to_class ('_ meta' Tệp "/Người dùng/Salishkumar/Backend/Tiffinwala/Ven v/lib/python3.9/trang web gói/django/db/model/base.py ", dòng 326, trong add_to_class value.contribution_to_class (cls, tên) tệp" hoặc phụ trợ/tiffinwala/venv/lib/python3.9/trang web trang web/django/utils/kết nối.py ", dòng 15, trong getattr return getattr (self._connections [self._alias] /backend/tiffinwala/venv/lib/python3.9/site-packages/django/utils/connection.py ", dòng 62, trong getItem Conn = self.create_connection (bí danh) Venv/lib/python3.9/trang web trang web/django/db/utils.py ", dòng 204, trong create_connection backend = load_backend (db ['động cơ']) lib/python3.9/trang web trang web/django/db/utils.py ", dòng 111, trong load_backend return_module ('%s.base ' % backend_name) Tệp "/người sử dụng /Users /tiffinwala/venv/lib/python3.9/site-packages/mysqldb/init.py ", dòng 24, trong phiên bản_info, _mysql.Version_info File "/Users/salishkumar/backend/tiffinwala/manage.py", line 22, in main() File "/Users/salishkumar/backend/tiffinwala/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/core/management/init.py", line 425, in execute_from_command_line utility.execute() File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/core/management/init.py", line
401, in execute django.setup() File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/init.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate app_config.import_models() File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/apps/config.py", line 300, in import_models
self.models_module = import_module(models_module_name) File "/Users/salishkumar/opt/anaconda3/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 986, in _find_and_load_unlocked File "", line 680, in _load_unlocked File "", line 850, in exec_module File "", line 228, in _call_with_frames_removed File
"/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/contrib/auth/models.py", line 3, in from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 47, in class AbstractBaseUser(models.Model): File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/db/models/base.py", line 122, in new
new_class.add_to_class('_meta', Options(meta, app_label)) File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class value.contribute_to_class(cls, name) File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/db/models/options.py", line 207, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File
"/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/utils/connection.py", line 15, in getattr return getattr(self._connections[self._alias], item) File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/utils/connection.py", line 62, in getitem conn = self.create_connection(alias) File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/db/utils.py", line 204, in create_connection backend =
load_backend(db['ENGINE']) File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/db/utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "/Users/salishkumar/opt/anaconda3/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/django/db/backends/mysql/base.py", line 15,
in import MySQLdb as Database File "/Users/salishkumar/backend/tiffinwala/venv/lib/python3.9/site-packages/MySQLdb/init.py", line 24, in version_info, _mysql.version_info, _mysql.file NameError: name '_mysql' is not defined
MySQL có sẵn cho M1 Mac không?
Có (8.0 [Homebrew]) thông qua Homebrew, MySQLD có thể được cài đặt với hỗ trợ M1 gốc.
Through homebrew, mysqld can be installed with native m1 support.
Làm cách nào để tải xuống mysqlclient trên mac?
Cài đặt MySQL và MySQLClient (Python) trong macOS.. Bước một: Cài đặt homebrew .. Bước hai: Cài đặt MySQL .. Bước ba: Cài đặt MySQL-Connector-C .. Bước bốn: Cài đặt Xcode-Select .. Bước năm: Cài đặt OpenSSL .. Bước sáu: Không liên kết MySQL và liên kết MySQL-Connector-C .. Bước bảy: Cài đặt MySQLClient .. Bước tám: Liên kết lại MySQL ..
Django có cần mysqlclient không?
Django yêu cầu mysqlclient 1.4.. |