【问题标题】:Can't install msqlclient for django/python3 [OSX 10.12.4]无法为 django/python3 [OSX 10.12.4] 安装 msqlclient
【发布时间】:2017-09-23 14:12:24
【问题描述】:

当我运行 python3 manage.py runserver 时,我收到了这条消息:

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. 
Did you install mysqlclient or MySQL-python?

因为我在 python 上使用 mysql 数据库,所以我尝试使用 pip3 安装 mysqlclient 我得到另一个错误:

Collecting mysqlclient
  Using cached mysqlclient-1.3.10.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup_posix.py", line 54, in get_config
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/setup_posix.py", line 12, in dequote
        if s[0] in "\"'" and s[0] == s[-1]:
    IndexError: string index out of range  

       ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-wt6g2_0e/mysqlclient/

我也在网上读到python3不支持mysqlclient,但是在尝试安装MySQL-python时遇到类似的错误:

 Collecting MySQL-python
  Using cached 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/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-jp09s51k/MySQL-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/private/var/folders/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-jp09s51k/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/dd/vlr9cjt17_j4ccyzz89mld1w0000gn/T/pip-build-jp09s51k/MySQL-python/

我该如何解决这个问题并为 python 安装 mysql 客户端,或者是否有其他方法可以在 python 中使用 MySQL db?

编辑:python3 确实支持 mysqlclient 但不支持 MySQL-python。

【问题讨论】:

  • 您缺少 Python MySQL“驱动程序”。这里有一个关于如何安装的答案:stackoverflow.com/a/25865271/190823
  • 运行后:'brew install mysql-connector-c' 我得到了消息,它已经安装了“警告:mysql-connector-c-6.1.9 已经安装”并运行 pip install MySQL-python 抛出同样的错误。
  • 我在网上看到python3不支持mysqlclient,但是在尝试安装mysql-python时遇到了类似的错误。你有错误的方式。 MySQL-python 仅支持 Python 2。如果您使用的是 Python 3,则需要 mysqlclient。
  • 是的,我对那个不好。两者仍然出现相同的错误

标签: python mysql django macos


【解决方案1】:

我不确定我做了什么,但我认为我的问题是我有一个糟糕的$PATH。我试图执行我在 Google 上找到的步骤之一,在重置 bash_profile 并再次设置 Python 路径后,它对我来说是固定的。

【讨论】:

    猜你喜欢
    • 2017-10-30
    • 2016-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-23
    • 2015-09-22
    相关资源
    最近更新 更多