pip install mysqlclient returns "fatal error C1083: Cannot open file: 'mysql.h': No such file or directory

Question:

Here is this issue:
I attempt to install mysqlclient like so

C:Usersamccommon349>pip install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/ec/fd/83329b9d3e14f7344d1
cb31f128e6dbba70c5975c9e57896815dbb1988ad/mysqlclient-1.3.13.tar.gz
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command c:usersamccommon349appdatalocalprogramspythonpython36python.exe -u -c "import setuptools, tokenize;__file__='C:\Users\AMCCOM~1\AppData\Local\Temp\pip-install-qcgo48hf\mysqlclient\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('rn', 'n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:UsersAMCCOM~1AppDataLocalTemppip-record-q4yoftj8install-record.txt --single-version-externally-managed --compile:

c:usersamccommon349appdatalocalprogramspythonpython36libdistutilsdist.py:261: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
running install
running build
running build_py
creating build
creating buildlib.win-amd64-3.6
copying _mysql_exceptions.py -> buildlib.win-amd64-3.6
creating buildlib.win-amd64-3.6MySQLdb
copying MySQLdb__init__.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbcompat.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbconnections.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbconverters.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbcursors.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbrelease.py -> buildlib.win-amd64-3.6MySQLdb
copying MySQLdbtimes.py -> buildlib.win-amd64-3.6MySQLdb
creating buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstants__init__.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsCLIENT.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsCR.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsER.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsFIELD_TYPE.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsFLAG.py -> buildlib.win-amd64-3.6MySQLdbconstants
copying MySQLdbconstantsREFRESH.py -> buildlib.win-amd64-3.6MySQLdbconstants
running build_ext
building '_mysql' extension
creating buildtemp.win-amd64-3.6
creating buildtemp.win-amd64-3.6Release
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsVCToolsMSVC14.14.26428binHostX86x64cl.exe /c/nologo/Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1include" -Ic:usersamccommon349appdatalocalprogramspythonpython36include -Ic:usersamccommon349appdatalocalprogramspythonpython36include "-IC:Program Files (x86)Microsoft Visual Studio2017BuildToolsVCToolsMSVC14.14.26428include" "-IC:Program Files (x86)Windows KitsNETFXSDK4.6.1includeum" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0ucrt" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0shared" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0um" "-IC:ProgramFiles (x86)Windows Kits10include10.0.17134.0winrt" "-IC:Program Files (x86)Windows Kits10include10.0.17134.0cppwinrt" /Tc_mysql.c /Fobuildtemp.win-amd64-3.6Release_mysql.obj /Zl _mysql.c
_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\2017\BuildTools\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\cl.exe' failed with exit status 2

I made sure I had all of the files needed from visual studios build tools, I downloaded the mysql-python connector, and updated my pip and setup tools. I am a complete beginner to this and would appreciate any input as to how to go about fixing this error.

Asked By: Aaron McCommon

||

Answers:

You can download unofficial windows binaries for your python version using https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient. Then install it using pip. This way you’ll be able to avoid the hassle of dealing with visual studio build tools.

Just download the mysqlclient.whl file most applicable to you. I think in your case it’ll be

mysqlclient‑1.3.13‑cp36‑cp36m‑win_amd64.whl

and run

pip install "path to the downloaded .whl file"
Answered By: Nipun Thennakoon

This is a problem with the 64 bit version of python on Windows 10. The following repaired the problem for me.

  1. Install the 32 bit version of python for windows (currently version 3.7.1)
  2. Install visual studio build tools
    https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017
    for C++
  3. Install the 32 bit mysql connector version 6.1.11 from https://downloads.mysql.com/archives/c-c/

After this I was able to install mysqlclient with pip install mysqlclient.

Hopefully someone will come up with a better solution that doesn’t require downgrading to 32 bit because this is not a good solution, it just works. I found a way to work around the mysql issue but ran into the problem again while trying to install channels. It seems python 64 bit is looking for 32 bit libraries instead of 64 bit libraries on windows. So far this solution has solved all of my python build problems on windows.

Answered By: Ralph Ritoch

I had this issue (exactly same error) and tried all the solutions mentioned above, and neither of them worked (at least for me), actually I was about to pull my hairs over this issue till I found the solution in a very weird, simple and stupid way!! .

I did the following steps so that the problem solved and life got sweet again.

First I installed MySQL Connector/C from here

Second (after installation finished) I copied MySQL Connector C 6.1 folder from Program files/MySQL into Program files (x86)/MySQL

note that you might have to create MySQL folder if it doesn’t exist in Program files (x86) (it didn’t exist for me)

As simple as that, it worked for me, it seems for some (or all) 64-bit windows, pip or more probably mysqlclient setup script only searches Program files (x86) folder for some MySQL files (such as ‘mysql.h’) and doesn’t search Program files and since doesn’t find anything in Program files (x86) raises the error very dumb!!! isn’t it

Answered By: Code_Worm

This error occurs when trying to install mysqlclient for python32 in 64 bit environments.
Uninstall python and re-install 64 bit version. Then pip install mysqlclient will run with no errors.

In Command Line, Just type:

python --

instead of:

python --version

(This should show more details about the version including whether it is 32 or 64 bit)

Answered By: Ahmedakhtar11

Wasted a lot of time to solve this error i found the solution that worked for me at least.

When i tried to install MYSQL Client

pip install mysqlclient

1st error

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


And also tried to install Django Channels

pip install -U channels

2nd error

error: Microsoft Visual C++ 14.0 is required. Get it with “Microsoft Visual C++ Build Tools”: https://visualstudio.microsoft.com/downloads/

Download Build tools :
Microsoft Build Tools

Stack overflow :
How to install/select required Build Tools

Installed build tools. (Happy Coding)


@Ralph Ritoch solution worked for me and as well others those getting Mysql Client error.

But i also installed Django Channels so i followed these steps mentioned below

Follow these steps

  1. Windows 10 64 bit
  2. Python 64 bit 3.7.3
  3. mysql-connector-c-6.1.11-winx64
  4. Build tools

I also installed Django Channels 2.2.0 and not getting any kind of error.

Successfully installed mysqlclient


(Note)

MySQL connector already installed into x86 directory

Copy c:Program FilesMySQLMySQL Connector C 6.0.2 directory to c:Program Files (x86)MySQLMySQL Connector C 6.1

So i did not changed the directory of MySQL Connector. (You can also check this)

Maybe work for you!

Other Stack solution to change dirctory


Possible Reasons

Why we getting errors.

  1. Python 32/64 bit Version
  2. MySQL Connector 32/64 bit version
  3. Directory issue
  4. Window 32/64 bit version
  5. Build Tools not installed (If getting Microsoft Visual C++ 14.0 is required)

Thanks to all who posted their solution.

Well probably,this is one of the stupidest errors i have ever witnessed.
I have Python 3.7.3 32bit along with latest pip3 and i was installing wheels to my Python….and i stumbled on this STUPID error….
Probably my situation is a bit different but you can resolve it just by looking carefully at the error…. at first it seems something is missing and you start blaming you, Windows ,32/64bit and the list goes on and on..
Take a step back…just take a step back and just read the nasty red error message…. read it really well.
In my case it was

ERROR: Command errored out with exit status 1:
     command: 'c:usersmyUserNameappdatalocalprogramspythonpython37-32python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\MASTER~1\AppData\Local\Temp\pip-install-z7x81g2q\mysqlclient\setup.py'"'"'; __file__='"'"'C:\Users\MASTER~1\AppData\Local\Temp\pip-install-z7x81g2q\mysqlclient\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersMASTER~1AppDataLocalTemppip-record-z1mvci5vinstall-record.txt' --single-version-externally-managed --compile
         cwd: C:UsersMASTER~1AppDataLocalTemppip-install-z7x81g2qmysqlclient
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating buildlib.win32-3.7
    creating buildlib.win32-3.7MySQLdb
    copying MySQLdb__init__.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdb_exceptions.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbcompat.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbconnections.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbconverters.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbcursors.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbrelease.py -> buildlib.win32-3.7MySQLdb
    copying MySQLdbtimes.py -> buildlib.win32-3.7MySQLdb
    creating buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstants__init__.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsCLIENT.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsCR.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsER.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsFIELD_TYPE.py -> buildlib.win32-3.7MySQLdbconstants
    copying MySQLdbconstantsFLAG.py -> buildlib.win32-3.7MySQLdbconstants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating buildtemp.win32-3.7
    creating buildtemp.win32-3.7Release
    creating buildtemp.win32-3.7ReleaseMySQLdb
    C:Program Files (x86)Microsoft Visual Studio2019BuildToolsVCToolsMSVC14.21.27702binHostX86x86cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1includemariadb" -Ic:usersMyUserNameappdatalocalprogramspythonpython37-32include -Ic:usersMyUserNameappdatalocalprogramspythonpython37-32include "-IC:Program Files (x86)Microsoft Visual Studio2019BuildToolsVCToolsMSVC14.21.27702include" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0ucrt" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0shared" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0um" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0winrt" "-IC:Program Files (x86)Windows Kits10include10.0.17763.0cppwinrt" /TcMySQLdb/_mysql.c /Fobuildtemp.win32-3.7ReleaseMySQLdb/_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\BuildTools\VC\Tools\MSVC\14.21.27702\bin\HostX86\x86\cl.exe' failed with exit status 2
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'c:usersMyUserNameappdatalocalprogramspythonpython37-32python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\Users\MASTER~1\AppData\Local\Temp\pip-install-z7x81g2q\mysqlclient\setup.py'"'"'; __file__='"'"'C:\Users\MASTER~1\AppData\Local\Temp\pip-install-z7x81g2q\mysqlclient\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UsersMASTER~1AppDataLocalTemppip-record-z1mvci5vinstall-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

Have you read it well ?…i assume that you have everything … the Build tools, the MySQL Connector C 6.1…you even moved it to Program Files (x86)…so what it wrong…?? …
Now take a closer look

C:Program Files (x86)Microsoft Visual Studio2019BuildToolsVCToolsMSVC14.21.27702binHostX86x86cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MT -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 "-IC:Program Files (x86)MySQLMySQL Connector C 6.1includemariadb" -

I am pretty sure you saw it…STILL NO ?…. let me bold it for you

"-IC:Program Files (x86)MySQLMySQL Connector C 6.1includemariadb" -

mariadb
Well it can’t be any stupidest than this …the installer looks for mariadb includes and later libs
Just go to the mariadb site and download the MariaDB C/C++ connector and install it…
Well its not over..
Goto to C:Program Files (x86)MySQLMySQL Connector C 6.1include
and create folder mariadb…and copy paste the contents from the mariaDb connector installation include folder
again don’t go way…go to
C:Program Files (x86)MySQLMySQL Connector C 6.1lib and do again the same drill for the lib folder
so you should have

C:Program Files (x86)MySQLMySQL Connector C 6.1includemariadb  

C:Program Files (x86)MySQLMySQL Connector C 6.1libmariadb  

Now hit the pip3 install mysqlclient
and enjoy installing without a nag…the end

Successfully installed mysqlclient-1.4.2.post1
Answered By: John

I was trying the same for a Django project.
I tried using:
pip install mysql-python
which gave me the following error:
'mysql.h': No such file or directory.

After fiddling with requirements.txt which gave me yet another error

  Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB) 
    Complete output from command python setup.py egg_info: 
    Traceback (most recent call last): 
      File "<string>", line 1, in <module> 
      File "/tmp/pip-install-43_6cfva/MySQL-python/setup.py", line 13, in <module> 
        from setup_posix import get_config 
      File "/tmp/pip-install-43_6cfva/MySQL-python/setup_posix.py", line 2, in <module> 
        from ConfigParser import SafeConfigParser 
    ModuleNotFoundError: No module named 'ConfigParser' 

Finally using this worked for me:
pip install mysql-connector
import mysql.connector

Answered By: Amal Matty Antony

None of the solutions above worked for me. Apparently I had to downgrade my Python from 3.7.x to 3.6.4 and that solved the problem for me. Downloadlink for python=3.6.4.

I would recommend to create a new virtual environment for this and not to uninstall your main python. Find extensive documentation on how to create a venv here.

Answered By: Erfan

I wanted to comment on John’s answer but my comment was too long so I had to make another answer. Sorry for that.

John, this helped me a lot, thanks. Not properly reading the logs is a bad habit for many people, myself included.

But instead of downloading the mariadb connector (or searching the net for a prebuilt wheel), I managed to do it with oracle’s mysql connector. And I prefer to do symbolic links instead of copying files. Here’s what I did using windows 10 x64, python 3.8 x64 and oracle’s mysql connector x64:

# run this on an elevated command prompt if your user does not have permission to make symbolic links
# download and install https://downloads.mysql.com/archives/c-c/
mklink /d "C:Program FilesMySQLMySQL Connector C 6.1includemariadb" "C:Program FilesMySQLMySQL Connector C 6.1includemysql"
mklink /d "C:Program Files (x86)MySQL" "C:Program FilesMySQL"
mklink /d "C:Program FilesMySQLMySQL Connector C 6.1libmariadb" "C:Program FilesMySQLMySQL Connector C 6.1libvs14"
mklink "C:Program FilesMySQLMySQL Connector C 6.1libvs14mariadbclient.lib" "C:Program FilesMySQLMySQL Connector C 6.1libvs14mysqlclient.lib"
SET INCLUDE=C:Program FilesMySQLMySQL Connector C 6.1include;%INCLUDE%
python3 -m pip install mysqlclient

And that’s it.

Answered By: gnumaru

This is what solved my issue

  • Install MySQL Connector/C (Archived Versions) from here

It is probably installed in the following location
C:Program FilesMySQLMySQL Connector C 6.1


  • Copy the entire folder MySQL Connector C 6.1 to C:Program Files (x86)MySQLMySQL Connector C 6.1

  • Try executing the command pip3 install mysqlclient.

Successful? Good Job!


Unsuccessful?


  • Install MariaDB connector from here

Probably installed in the location

C:Program FilesMariaDBMariaDB Connector C 64-bit

  • Copy the contents from

C:Program FilesMariaDBMariaDB Connector C 64-bitinclude

and Paste into a folder.
Name it as mariadb and paste it to the location

C:Program Files (x86)MySQLMySQL Connector C 6.1include


  • Copy the contents from

    C:Program FilesMariaDBMariaDB Connector C 64-bitlib

and Paste into a folder name it as mariadb and paste it to the location

`C:Program Files (x86)MySQLMySQL Connector C 6.1lib`

  • Try executing the command pip3 install mysqlclient.

This worked for me

Answered By: SohailAQ

Thanks for all the answers, but it was not sufficient to solve my problem. However it put me on the right path :).
To solve the error of the missing sys/types.h I had to copy this types.h file from “c:Program Files (x86)Windows Kits10Include10.0.17763.0ucrtsys” to “c:Program Files (x86)MySQLMySQL Connector C 6.1includemariadbsys”. Then I could finally install mysqlclient.

Answered By: nerd01

for me, pip install mysqlclient was throwing error…

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.20.27508\bin\HostX86\x86\cl.exe' failed with exit status 2

It seems mysqlclient is 64 bit.
So I Forced both Python and pip to execute from the 64 bit directory.

Explicitly…

don’t run python -m venv myvemv and pip install -r requirements.txt,

run the following…

C:UsersmrAppDataLocalProgramsPythonPython37python -m venv [path to your virtual env goes here]

and

C:UsersmrAppDataLocalProgramsPythonPython37Scriptspip install -r requirements.txt
Answered By: mrivas

In order to solve it, I’ve gone to this page

enter image description here

and downloaded mysqlclient‑1.4.6‑pp373‑pypy36_pp73‑win32.whl.

Then, placed it in a particular folder, opened the terminal in it, activated the virtual environment venv and ran

pip install mysqlclient-1.4.6-cp39-cp39-win_amd64.whl

enter image description here

Answered By: Tiago Martins Peres

sometimes the error is of interpreter too, it was in my case. I was using 3.8 python and had installed it in D:/, so that’s and was not installed properly.

So I uninstalled it and installed it again correctly and it worked.

Answered By: 56 Tejas Powar

There are other ways to install mysqlclient into your system, I was not able to install it directly through command prompt it showed:

Fatal error in launcher: Unable to create process

tried couple of other alternatives and got a solution:

  • Click on start
  • Search for python and click on open file location
    click on open file location
  • 3.Click on python(version e.g=2.7,3.8,3.9…etc)
    right-click and open file location
  • 4.Click on scripts
  • 5.Got to path on the top of the file explorer and type cmd
    1. After command prompt opens type pip install mysqlclient
  • 7.Installation starts and now you have mysqlclient in your system
Answered By: Vaishnavi Tyra

We can do so many things but if we miss to do python 64 bit in the 64 bit environment, the setup will not be completed.

So, we must confirm python 64 bit if our windows is 64 bit.

To see that you are in 64 bit or 32 bit, please run python command in the command prompt and see the result as like below:

To check 32 or 64 bit of python

Answered By: Md. Majharul Haque

I encounter the same problem while installing mysqlclient from pip, there is no need to download .whl files manually you can specify the version of the package you require.Below is my solution:

pip install mysqlclient==1.4.6

Thank You.

Answered By: d3vkidhash

My requirement was version 1.4.6 so this worked for me. Also shared here https://stackoverflow.com/a/74758867/9674385.

pip install mysqlclient==1.4.6

Answered By: Bella

Just want to share how I resolve it. I downgraded it to Python version 3.10 rather than using the new version 3.12. I tried all the solutions above but it did not fix the issue. So I tried to copy all my settings on my laptop and replicate it on my desktop and that solved my issue. Maybe in the future, they will fix it on the 3.12. But for now, it works fine.

By the way, the first error I got was Microsoft Visual 14 or higher after I fixed that issue it was a quick fix. That error came out
fatal error C1083: Cannot open include file: 'mysql.h' When I install all the requirments.

I tried downloading the .whl file but still does not work. Maybe this would also help other people who still have this issue. By the way, almost all servers where you host your Python/Django app have lower Python Versions.

Answered By: poliam

There is a fairly simple way to solve this: install the latest version with:

pip install mysqlclient

Using version 1.4.6 resulted in failure after failure. However, remove the version requirement and 2.1.1 installed without error.

Joe White

Answered By: Joseph White

The previous answer won’t work for everybody.
Inspect the error carefully. Sometimes the compiler tries to include the directory C:/mariadb-connector/include/mariadb.

The error message in my case had this : -IC:/mariadb-connectorincludemariadb
Here’s what I did:

  1. Installed mariadb c connector
  2. made a folder names mariadb-connector at the root of the drive C
  3. pasted the contents of C:Program FilesMariaDBMariaDB Connector C 64-bit in the mariadb-connector that I created.

And it worked.

Answered By: trp

I got a similar error with python 3.12 on windows 10

PS C:Usersjuanf> pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.2.0.tar.gz (89 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (pyproject.toml) ... error
  error: subprocess-exited-with-error

  × Building wheel for mysqlclient (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [46 lines of output]
      # Options for building extention module:
        library_dirs: ['C:/mariadb-connector\lib\mariadb', 'C:/mariadb-connector\lib']
        libraries: ['kernel32', 'advapi32', 'wsock32', 'shlwapi', 'Ws2_32', 'crypt32', 'secur32', 'bcrypt', 'mariadbclient']
        extra_link_args: ['/MANIFEST']
        include_dirs: ['C:/mariadb-connector\include\mariadb', 'C:/mariadb-connector\include']
        extra_objects: []
        define_macros: [('version_info', (2, 2, 0, 'final', 0)), ('__version__', '2.2.0')]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating buildlib.win-amd64-cpython-312
      creating buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdbconnections.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdbconverters.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdbcursors.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdbrelease.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdbtimes.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdb_exceptions.py -> buildlib.win-amd64-cpython-312MySQLdb
      copying srcMySQLdb__init__.py -> buildlib.win-amd64-cpython-312MySQLdb
      creating buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsCLIENT.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsCR.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsER.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsFIELD_TYPE.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstantsFLAG.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      copying srcMySQLdbconstants__init__.py -> buildlib.win-amd64-cpython-312MySQLdbconstants
      running egg_info
      writing srcmysqlclient.egg-infoPKG-INFO
      writing dependency_links to srcmysqlclient.egg-infodependency_links.txt
      writing top-level names to srcmysqlclient.egg-infotop_level.txt
      reading manifest file 'srcmysqlclient.egg-infoSOURCES.txt'
      reading manifest template 'MANIFEST.in'
      adding license file 'LICENSE'
      writing manifest file 'srcmysqlclient.egg-infoSOURCES.txt'
      copying srcMySQLdb_mysql.c -> buildlib.win-amd64-cpython-312MySQLdb
      running build_ext
      building 'MySQLdb._mysql' extension
      creating buildtemp.win-amd64-cpython-312
      creating buildtemp.win-amd64-cpython-312Release
      creating buildtemp.win-amd64-cpython-312Releasesrc
      creating buildtemp.win-amd64-cpython-312ReleasesrcMySQLdb
      "C:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.37.32822binHostX86x64cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD "-Dversion_info=(2, 2, 0, 'final', 0)" -D__version__=2.2.0 -IC:/mariadb-connectorincludemariadb -IC:/mariadb-connectorinclude -IC:Python312include -IC:Python312Include "-IC:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.37.32822include" "-IC:Program FilesMicrosoft Visual Studio2022CommunityVCToolsMSVC14.37.32822ATLMFCinclude" "-IC:Program FilesMicrosoft Visual Studio2022CommunityVCAuxiliaryVSinclude" "-IC:Program Files (x86)Windows Kits10include10.0.22621.0ucrt" "-IC:Program Files (x86)Windows Kits10\include10.0.22621.0\um" "-IC:Program Files (x86)Windows Kits10\include10.0.22621.0\shared" "-IC:Program Files (x86)Windows Kits10\include10.0.22621.0\winrt" "-IC:Program Files (x86)Windows Kits10\include10.0.22621.0\cppwinrt" "-IC:Program Files (x86)Windows KitsNETFXSDK4.8includeum" /Tcsrc/MySQLdb/_mysql.c /Fobuildtemp.win-amd64-cpython-312Releasesrc/MySQLdb/_mysql.obj
      _mysql.c
      src/MySQLdb/_mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
      error: command 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.37.32822\bin\HostX86\x64\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects

[notice] A new release of pip is available: 23.2.1 -> 23.3.1
[notice] To update, run: python.exe -m pip install --upgrade pip

After some time i found two possible solutions:

  1. Download the .whl file from the official pypi page for mysqlclient (https://pypi.org/project/mysqlclient/#files) and install it using pip install "your whl file location"

  2. Download the MariaDB conector for your OS from (https://mariadb.com/downloads/connectors/) and install it. I notice the mariadb connector was being searched in a different folder than the one its installed by default library_dirs: ['C:/mariadb-connector\lib\mariadb', 'C:/mariadb-connector\lib']. So, move the install files from C:Program FilesMariaDBMariaDB Connector C to C:mariadb-connector. Make sure you also have Microsft Visual Studio C++ Build Tools installed (For this download Visual Studio Community). After that execute pip install mysqlclient

Second option was the one i used, but both should work.

Edit:

You need to reinstall maria DB connector (in the default folder) for the library to work properly.

i just downgraded my pyhton version to 3.8 and it worked perfectly

Answered By: med ouadjih boudraa

read the error, its looking for mariadb connectors in -IC:/mariadb-connectorincludemariadb. download mariadb-connector "C connector" from https://mariadb.com/downloads/connectors/connectors-data-access/c-connector/ and install. go to installation folder C:Program FilesMariaDBMariaDB Connector C 64-bit and copy MariaDB Connector C 64-bit folder to the location its looking for in your case -IC:/mariadb-connectorincludemariadb. so you should past it in C:/ and rename it to mariadb-connector so it can find it.

Answered By: amir jj

Try:

pip install --only-binary :all: mysqlclient
Answered By: Italo Ramon

I don’t understand no one looked at the documentation, just install MariaDB Connector and set the environment variable MYSQLCLIENT_CONNECTOR to the root path of the mariadb connector (not mariadb). This was the only thing, that worked for my windows 11 pc

Answered By: GuiTaek
Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.