mac django错误您安装了mysqlclient还是MySQL-python?

时间:2018-07-17 13:59:38

标签: django django-rest-framework django-mysql

我正在尝试在Mac上设置django rest项目。每当我运行python manage.py makemigrations时,都会显示:Did you install mysqlclient or MySQL-python?错误。但是,它们两个都已经安装。

完整堆栈跟踪:

    (VB_env) staff-207-213:VB_Backend_SCG nitishpatkar$ python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute
    django.setup()
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models()
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
    class AbstractBaseUser(models.Model):
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/models/base.py", line 124, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/models/base.py", line 325, in add_to_class
    value.contribute_to_class(cls, name)
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/models/options.py", line 214, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
    return import_module('%s.base' % backend_name)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 30, in <module>
    'Did you install mysqlclient or MySQL-python?' % e
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/_mysql.so, 2): Symbol not found: _mysql_affected_rows
  Referenced from: /Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/_mysql.so
  Expected in: flat namespace
 in /Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages/_mysql.so.
Did you install mysqlclient or MySQL-python?
(VB_env) staff-207-213:VB_Backend_SCG nitishpatkar$ pip install mysqlclient
Requirement already satisfied: mysqlclient in /Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages (1.3.13)
(VB_env) staff-207-213:VB_Backend_SCG nitishpatkar$ pip install mysql-python
Requirement already satisfied: mysql-python in /Users/nitishpatkar/Development/Vision Backlog rewrite/VB_env/lib/python2.7/site-packages (1.2.5)
(VB_env) staff-207-213:VB_Backend_SCG nitishpatkar$ 

1 个答案:

答案 0 :(得分:0)

实际问题是

Symbol not found: _mysql_affected_rows

即无法加载MySQL Python模块,因为操作系统无法在操作系统的MySQL客户端库中找到应该存在的符号,这可能是由于它们已过时造成的。

例如在这样的问题:Django - MySQLdb: Symbol not found: _mysql_affected_rows

如何实际解决此问题取决于您最初安装这些库的方式(例如,使用brew?)。