skip to Main Content

I already tried to install wheel — didn’t work well.
Tried to install build tools — didn’t work
Tried to install mysql connector/C and put it in the environment variables — didn’t work
tried upgrading pip — didn’t work

So this is my error:

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 Files (x86)Microsoft Visual Studio2022BuildToolsVCToolsMSVC14.38.33130binHostX86x64cl.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:UsersAdministratorDesktopPython Projectstastematesinclude" -IC:UsersAdministratorAppDataLocalProgramsPythonPython312include -IC:UsersAdministratorAppDataLocalProgramsPythonPython312Include "-IC:Program Files (x86)Microsoft Visual Studio2022BuildToolsVCToolsMSVC14.38.33130include" "-IC:Program Files (x86)Microsoft Visual Studio2022BuildToolsVCAuxiliaryVSinclude" "-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" /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 (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\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

2

Answers


  1. When asking questions, it’s a good idea to let people know what OS you’re on. Helps others answer the question.

    On Linux/Ubuntu – mysql.h is missing, so install "sudo apt install libmysqlclient-dev" (Centos – sudo yum install mysql-devel -y)

    On windows, I think it’s simply a matter of installing the mysql client.

    References:

    1. mysql.h file can't be found
    2. pip install mysqlclient returns "fatal error C1083: Cannot open file: 'mysql.h': No such file or directory
    Login or Signup to reply.
  2. try pip install mysql-connector-python

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search