Hướng dẫn nameerror: name _mysql is not defined mac m1 - nameerror: name _mysql không được xác định mac m1
I am trying to include mysql into my django and face the error of
I think this might be an error due to the new M1 chip and mac OS system, but I can't figure out how to fix it. (I am using mac Monterey with M1 chip.) Here is the package version:
I've read it somewhere about my python needs to be at the homebrew directory, but not sure how to do it.
I've also seen other solution of using
It didnt work for me. here is my .zshrc file now
and here is my bash_profile Are you on a new Mac ARM chip, working on a Django project, and using MySQL as your backend DB? This article is aimed at you. And maybe, just maybe, you got this weird error when trying to runserver or migrate. "NameError: name ‘_mysql’ is not defined", then this article is definitely for you. I'm not one to give long introductions about why I'm working in Django, how long I spent trying to fix this (though I'd love to brag about it), or giving you some life story like the blogs for
recipes do, so let's get to it. A man named Adam Johnson comes to our rescue here, and the problem solution is listed in more depth here. That article pretty much outlines it. I've tried this solution using both Conda and Pipenv, and it's worked in both. So, from an environment perspective we have something that should work at least from these two approaches. To
install using Pipenv: Navigate to the folder where your environment is in pipenv shell pipenv install pymysql To install using Conda: conda activate {env_name} pip install pymysql Note: I pretty much use pip for everything and I avoid Homebrew like the plague because it frequently causes clashes between Brew and Conda. I manage my environments in CondaForge, download packages from pip where I can, and use Forge for everything else. The CodeThat's the installation. Now, for the code part, it's pretty simple. At the beginning of the settings.py in my main folder, I add:
Followed by, somewhere near the top of this file (I added it after the databases section):
Sam, Why Does this Work?Adam says it much better than I can even begin to explain. ConclusionNow, you should be able to do whatever you needed to do. I was migrating when I discovered the error and was able to migrate after this. Part of learning is debugging, and a lot of debugging is persistence. Hang in there, if this doesn't fix your problem, maybe it will give you a different error message. We will consider a different error message progress. If you benefitted from this story, send me a message via Medium or LinkedIn! I am an extrovert and thrive on making connections. I also believe connections open the door to discover what we want to do in life. Until next debug session, 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. ' 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 |