3

I'm trying to install mysqlclient to connect to my database with django, but get the following error:

(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/

I have the following in my settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'todo',
        'USER': 'root',
        'PASSWORD': 'password'
    }
}
1

5 Answers 5

5

If you see the document of mysqlclient, I think it make mighty help for you.

The document say:

Note that this is a basic step. I can not support complete step for build for all environment. If you can see some error, you should fix it by yourself, or ask for support in some user forum. Don't file a issue on the issue tracker.

You may need to install the Python 3 and MySQL development headers and libraries like so:

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

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

Then you can install mysqlclient via pip now:

$ pip install mysqlclient 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - I got error and your solution helped me. it looks python3-dev is a must for pyhon3
2
brew install mysql

fixed this for me

Comments

2

If you are on windows,

you can install mysqlclient using wheel from here.

Donwload the appropriate file as per your platform; for eg: if you are using python 3.6 and 32 bit python then download

mysqlclient‑1.3.13‑cp36‑cp36m‑win32.whl

After downloading it, copy it in C:/ Then install the file using following code:

pip3 install C:\mysqlclient‑1.3.13‑cp36‑cp36m‑win32.whl\

If you are using a virtual environment, then activate your virtual env before installing.

Comments

1

Please visit the following link which contains working pip installations for different os:

https://github.com/prasad01dalavi/python_packages_installations

for python2 in linux

sudo apt-get install -y python-dev libmysqlclient-dev && sudo pip install mysqlclient

Comments

0

For Ubuntu, you may also have to install other dependencies:

apt-get update
apt-get install python3-dev default-libmysqlclient-dev build-essential pkg-config

Then try (from your virtual environment)

python3 -m pip install mysqlclient

Or as root (NOT Recommended):

pip install mysqlclient

That works for me.

Combining

Error when installing mysqlclient

and

Mysqlclient cannot install via pip, cannot find pkg-config name

Comments