-1

I am trying to install mysqlclient and getting the following error.

C:\Users\Yash Patel>pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.4.6.tar.gz (85 kB)
Using legacy setup.py install for mysqlclient, since package 'wheel' is not installed.
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: 'c:\users\yash patel\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\YASHPA~1\\AppData\\Local\\Temp\\pip-install-sc96zvsc\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\YASHPA~1\\AppData\\Local\\Temp\\pip-install-sc96zvsc\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\YASHPA~1\AppData\Local\Temp\pip-record-diaiyo1_\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\yash patel\appdata\local\programs\python\python37-32\Include\mysqlclient'
         cwd: C:\Users\YASHPA~1\AppData\Local\Temp\pip-install-sc96zvsc\mysqlclient\
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.7
    creating build\lib.win32-3.7\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.7\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.7\MySQLdb
    creating build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.7\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.7\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win32-3.7
    creating build\temp.win32-3.7\Release
    creating build\temp.win32-3.7\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" "-Ic:\users\yash patel\appdata\local\programs\python\python37-32\include" "-Ic:\users\yash patel\appdata\local\programs\python\python37-32\include" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.7\Release\MySQLdb/_mysql.obj /Zl /D_CRT_SECURE_NO_WARNINGS
    _mysql.c
    MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
    error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:\users\yash patel\appdata\local\programs\python\python37-32\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\YASHPA~1\\AppData\\Local\\Temp\\pip-install-sc96zvsc\\mysqlclient\\setup.py'"'"'; __file__='"'"'C:\\Users\\YASHPA~1\\AppData\\Local\\Temp\\pip-install-sc96zvsc\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\YASHPA~1\AppData\Local\Temp\pip-record-diaiyo1_\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\yash patel\appdata\local\programs\python\python37-32\Include\mysqlclient' Check the logs for full command output.
scriptmonster
  • 2,741
  • 21
  • 29
Yash Patel
  • 1
  • 1
  • 1
  • Hi Welcome to stack overflow please read [how to ask?](https://stackoverflow.com/help/how-to-ask) . Include just enough code to allow others to reproduce the problem. For help with this, read [How to create a Minimal, Complete, and Verifiable example.](https://stackoverflow.com/help/minimal-reproducible-example) – EdoBen May 23 '20 at 10:43
  • Hello! This question was already asked and has an answer here: https://stackoverflow.com/a/51294860/2174832 . I hope that will help you. – matyas May 23 '20 at 11:05

1 Answers1

0

You need to have mysql client (the actual db client software) installed on your device. When mysql client is installed the source files will be available for python to compile mysqlclient python module.

There is an alternative for this module. You may install pymysql. However this module is not being recommended for production purposes. This module is pure python so not it would not give the required performance.

If you use pymylsq you need to add 2 lines on the manage.py so you may use runserver.

manage.py

import pymysql
pymysql.install_as_MySQLdb()

...
...
scriptmonster
  • 2,741
  • 21
  • 29