pip3 installation of mysqlclient fails due to wheel

  flask, flask-mysql, mysql, python, python-3.x

While trying to install flask-mysqldb, the dependency ‘mysqlclient’ failed to install (the wheel to be more specific). To try and fix this, I tried installing the dependency separately (with pip), but received the same error. I’ve read many of the replies to people with problems installing this dependency, but they seem to be having different errors to me. I am running python version 3.9.1 with pip version 21.3.1 on mac osx version 10.15.7.

The error output I receive for the pip installation of mysqlclient after $ pip3 install mysqlclient looks like this:

Collecting mysqlclient
  Using cached mysqlclient-2.0.3.tar.gz (88 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/local/opt/[email protected]/bin/python3.9 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/1x/tdd766p92l19rmbz2jk610q00000gp/T/pip-install-pga8xm3r/mysqlclient_527b89707f954fb4a38b3e5a5624c9c5/setup.py'"'"'; __file__='"'"'/private/var/folders/1x/tdd766p92l19rmbz2jk610q00000gp/T/pip-install-pga8xm3r/mysqlclient_527b89707f954fb4a38b3e5a5624c9c5/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/1x/tdd766p92l19rmbz2jk610q00000gp/T/pip-wheel-pdo9ur_t
       cwd: /private/var/folders/1x/tdd766p92l19rmbz2jk610q00000gp/T/pip-install-pga8xm3r/mysqlclient_527b89707f954fb4a38b3e5a5624c9c5/
  Complete output (46 lines):
  mysql_config --version
  ['8.0.27']
  mysql_config --libs
  ['-L/usr/local/Cellar/mysql/8.0.27/lib', '-lmysqlclient', '-lz', '-lzstd', '-lssl', '-lcrypto', '-lresolv']
  mysql_config --cflags
  ['-I/usr/local/Cellar/mysql/8.0.27/include/mysql']
  ext_options:
    library_dirs: ['/usr/local/Cellar/mysql/8.0.27/lib']
    libraries: ['mysqlclient', 'zstd', 'resolv']
    extra_compile_args: ['-std=c99']
    extra_link_args: []
    include_dirs: ['/usr/local/Cellar/mysql/8.0.27/include/mysql']
    extra_objects: []
    define_macros: [('version_info', "(2,0,3,'final',0)"), ('__version__', '2.0.3')]
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.15-x86_64-3.9
  creating build/lib.macosx-10.15-x86_64-3.9/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb
  copying MySQLdb/_exceptions.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb
  creating build/lib.macosx-10.15-x86_64-3.9/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.15-x86_64-3.9/MySQLdb/constants
  running build_ext
  building 'MySQLdb._mysql' extension
  creating build/temp.macosx-10.15-x86_64-3.9
  creating build/temp.macosx-10.15-x86_64-3.9/MySQLdb
  clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk -Dversion_info=(2,0,3,'final',0) -D__version__=2.0.3 -I/usr/local/Cellar/mysql/8.0.27/include/mysql -I/usr/local/include -I/usr/local/opt/[email protected]/include -I/usr/local/opt/sqlite/include -I/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.macosx-10.15-x86_64-3.9/MySQLdb/_mysql.o -std=c99
  In file included from MySQLdb/_mysql.c:29:
  In file included from /usr/local/Cellar/mysql/8.0.27/include/mysql/mysql.h:46:
  /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/types.h:217:10: fatal error: 'sys/_pthread/_pthread_condattr_t.h' file not found
  #include <sys/_pthread/_pthread_condattr_t.h>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1 error generated.
  error: command '/usr/bin/clang' failed with exit code 1
  ----------------------------------------
  ERROR: Failed building wheel for mysqlclient
  

It seems as if it’s trying to reference a c library, but I have no idea how to fix this error. Any help would be much appreciated.

Source: Python Questions

LEAVE A COMMENT