将Django连接到MySQL错误“您安装了mysqlclient吗?”

时间:2018-11-15 08:07:36

标签: mysql django

我想将Django项目连接到MySQL。 我已经安装了mysqlclient 但是当我迁移项目“ python3 manage.py migration”时 它有一个错误!!!

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?

我不知道该如何解决!请帮助我

我尝试$ pip3安装mysql-python 错误!像这样:

Collecting mysql-python
  Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/cb/1r_2zrwn7597fzs9ktv0jbhh0000gn/T/pip-install-n72xlj1k/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/var/folders/cb/1r_2zrwn7597fzs9ktv0jbhh0000gn/T/pip-install-n72xlj1k/mysql-python/setup_posix.py", line 2, in <module>


           from ConfigParser import SafeConfigParser
        ModuleNotFoundError: No module named 'ConfigParser'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/cb/1r_2zrwn7597fzs9ktv0jbhh0000gn/T/pip-install-n72xlj1k/mysql-python/

1 个答案:

答案 0 :(得分:1)

错误本身可以说明问题所在。

您尝试过

pip install mysql-python

如果这不起作用,请确保您具有python-dev install。如果您使用的是Ubuntu,请在下面使用。

apt-get install python3-mysqldb libmysqlclient-dev python-dev

对于Mac,请尝试此操作。

$ brew uninstall mysql
$ brew install mysql-connector-c
$ brew unlink mysql-connector-c
$ brew install mysql
$ pip install mysql-python