安装mysqlclient时出现错误

3
我正在尝试安装mysqlclient以便使用Django连接到我的数据库,但是出现以下错误:
(venv) dhcp-ccc-12919:project user$ pip3 install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/6f/86/bad31f1c1bb0cc99e88ca2adb7cb5c71f7a6540c1bb001480513de76a931/mysqlclient-1.3.12.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/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/mysqlclient/setup.py", line 17, in <module>
        metadata, options = get_config()
      File "/private/var/folders/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/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/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/mysqlclient/setup_posix.py", line 54, in <listcomp>
        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]
      File "/private/var/folders/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/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/l4/0f1p1xlj3hlbxr6rzgqzrxmh0000gn/T/pip-install-lo7y8khq/mysqlclient/

我在settings.py中有以下内容:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'todo',
        'USER': 'root',
        'PASSWORD': 'password'
    }
}

https://github.com/PyMySQL/mysqlclient-python/issues/169 - jspcal
5个回答

4

如果您查看mysqlclient的文档,我认为它会对您有很大帮助。

文档中写道:

请注意这是一个基本步骤。我们无法为所有环境提供完整的构建步骤。如果出现错误,您应该自己修复,或在用户论坛上寻求支持。不要在问题跟踪器上提交问题。

您可能需要安装Python 3和MySQL开发头文件以及库,如下所示:

$ sudo apt-get install python3-dev default-libmysqlclient-dev build-essential # Debian / Ubuntu

$ sudo yum install python3-devel mysql-devel # Red Hat / CentOS

现在您可以通过pip安装mysqlclient:

$ pip install mysqlclient 

谢谢 - 我遇到了错误,您的解决方案帮助了我。看来python3-dev对于python3是必须的。 - Danniel Little

2
如果您使用的是Windows操作系统,可以从这里下载wheel文件并安装mysqlclient。请根据您的平台下载相应的文件;例如,如果您使用的是Python 3.6和32位Python,则需要下载mysqlclient-1.3.13-cp36-cp36m-win32.whl文件。下载完成后,请将文件复制到C:/目录下,然后使用以下代码安装文件:
pip3 install C:\mysqlclient-1.3.13-cp36-cp36m-win32.whl\
如果您使用的是虚拟环境,请在安装之前激活您的虚拟环境。

2
brew install mysql

为我修复这个问题


1

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接