Search code examples
pythonmysqldjango

Cannot open include file: 'mysql.h': No such file or directory


I am trying to install requirements.txt of a django project and it is giving me the following error:

MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory

I have tried the following commands but they don't seem to work for me

Commands that I tried:

   pip install mysqlclient==1.3.4

   pip install --only-binary :all: mysqlclient

error:

Installing collected packages: mysqlclient, wheel, gunicorn, psycopg2, python-dateutil, numpy, pandas, django-pandas, kuchbhi, pyparsing, pulp, sqlalchemy, xlwt, django-bootstrap-modal-forms, MarkupSafe, jinja2, branca, certifi, urllib3, chardet, idna, requests, folium, django-widget-tweaks, googlemaps, decorator, ipython-genutils, traitlets, pywin32, jupyter-core, pyrsistent, attrs, more-itertools, zipp, importlib-metadata, jsonschema, nbformat, pyzmq, tornado, jupyter-client, pickleshare, backcall, parso, jedi, wcwidth, prompt-toolkit, colorama, pygments, ipython, ipykernel, testpath, defusedxml, pandocfilters, webencodings, bleach, mistune, entrypoints, nbconvert, pywinpty, terminado, Send2Trash, prometheus-client, notebook, widgetsnbextension, ipywidgets, geojson, gmaps, django-fullcalendar, geographiclib, geopy, pillow, brotli, django-brotli, zopfli, django-static-compress, django-clear-cache, pyjwt, djangorestframework, djangorestframework-simplejwt, djangorestframework-jwt, django-cors-headers
  Found existing installation: mysqlclient 1.3.12
    Uninstalling mysqlclient-1.3.12:
      Successfully uninstalled mysqlclient-1.3.12
  Running setup.py install for mysqlclient ... error
    Complete output from command c:\users\rahul\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Rahul\\AppData\\Local\\Temp\\pip-build-pul5j4z0\\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\Rahul\AppData\Local\Temp\pip-mn6g7opp-record\install-record.txt --single-version-externally-managed --compile:
    c:\users\rahul\appdata\local\programs\python\python36-32\lib\distutils\dist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build\lib.win32-3.6
    creating build\lib.win32-3.6\MySQLdb
    copying MySQLdb\__init__.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\_exceptions.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\compat.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\connections.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\converters.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\cursors.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\release.py -> build\lib.win32-3.6\MySQLdb
    copying MySQLdb\times.py -> build\lib.win32-3.6\MySQLdb
    creating build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\__init__.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\CLIENT.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\CR.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\ER.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win32-3.6\MySQLdb\constants
    copying MySQLdb\constants\FLAG.py -> build\lib.win32-3.6\MySQLdb\constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build\temp.win32-3.6
    creating build\temp.win32-3.6\Release
    creating build\temp.win32-3.6\Release\MySQLdb
    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\bin\HostX86\x86\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,4,1,'final',0) -D__version__=1.4.1 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include\mariadb" -Ic:\users\rahul\appdata\local\programs\python\python36-32\include -Ic:\users\rahul\appdata\local\programs\python\python36-32\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /TcMySQLdb/_mysql.c /Fobuild\temp.win32-3.6\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\\2019\\Community\\VC\\Tools\\MSVC\\14.23.28105\\bin\\HostX86\\x86\\cl.exe' failed with exit status 2

    ----------------------------------------
  Rolling back uninstall of mysqlclient
Command "c:\users\rahul\appdata\local\programs\python\python36-32\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\Rahul\\AppData\\Local\\Temp\\pip-build-pul5j4z0\\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\Rahul\AppData\Local\Temp\pip-mn6g7opp-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\Rahul\AppData\Local\Temp\pip-build-pul5j4z0\mysqlclient\

Solution

  • The problem is you're using a 32-bit version of Python 3.6, for which there aren't wheels (binary versions) for that version of mysqlclient.

    You can see here in the package file list that there is a Windows x32 wheel for 1.3.12 – try that.

    pip install mysqlclient==1.3.12
    

    If that fails to install the correct wheel, download mysqlclient-1.3.12-cp36-cp36m-win32.whl from the above listing, then install it with (e.g.) pip install ./mysqlclient-1.3.12-cp36-cp36m-win32.whl

    Better still, if you can, switch to the x64 version of Python.