3

I am trying to install mysqlclient on macOS BigSur(running on M1 chip mac) as a part of implementing django project using MySQL DB. However, I am getting below error:

Collecting mysqlclient
  Using cached mysqlclient-2.0.3.tar.gz (88 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: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/rs/vv5212l55ys7lk0vx4p87gxw0000gn/T/pip-install-73_o12ze/mysqlclient_23e4f763c971433c863260eda891b9d0/setup.py'"'"'; __file__='"'"'/private/var/folders/rs/vv5212l55ys7lk0vx4p87gxw0000gn/T/pip-install-73_o12ze/mysqlclient_23e4f763c971433c863260eda891b9d0/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/rs/vv5212l55ys7lk0vx4p87gxw0000gn/T/pip-record-jl3d35rj/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.9/include/python3.9/mysqlclient
         cwd: /private/var/folders/rs/vv5212l55ys7lk0vx4p87gxw0000gn/T/pip-install-73_o12ze/mysqlclient_23e4f763c971433c863260eda891b9d0/
    Complete output (41 lines):
    mysql_config --version
    ['8.0.22']
    mysql_config --libs
    ['-L/usr/local/mysql/lib', '-lmysqlclient', '-lssl', '-lcrypto', '-lresolv']
    mysql_config --cflags
    ['-I/usr/local/mysql/include']
    ext_options:
      library_dirs: ['/usr/local/mysql/lib']
      libraries: ['mysqlclient', 'resolv']
      extra_compile_args: ['-std=c99']
      extra_link_args: []
      include_dirs: ['/usr/local/mysql/include']
      extra_objects: []
      define_macros: [('version_info', "(2,0,3,'final',0)"), ('__version__', '2.0.3')]
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.9
    creating build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    creating build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.macosx-10.9-x86_64-3.9
    creating build/temp.macosx-10.9-x86_64-3.9/MySQLdb
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/usr/local/opt/openssl@1.1/include -Dversion_info=(2,0,3,'final',0) -D__version__=2.0.3 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.9/MySQLdb/_mysql.o -std=c99
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    error: command '/usr/bin/gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/rs/vv5212l55ys7lk0vx4p87gxw0000gn/T/pip-install-73_o12ze/mysqlclient_23e4f763c971433c863260eda891b9d0/setup.py'"'"'; __file__='"'"'/private/var/folders/rs/vv5212l55ys7lk0vx4p87gxw0000gn/T/pip-install-73_o12ze/mysqlclient_23e4f763c971433c863260eda891b9d0/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/rs/vv5212l55ys7lk0vx4p87gxw0000gn/T/pip-record-jl3d35rj/install-record.txt --single-version-externally-managed --compile --install-headers /Library/Frameworks/Python.framework/Versions/3.9/include/python3.9/mysqlclient Check the logs for full command output.

Please note that I have already checked out many questions opened for this same issue. But none of the suggested fix working for me. Please help

Shadow
  • 30,859
  • 10
  • 44
  • 56
Aman
  • 31
  • 4

2 Answers2

0

This Issue is fixed now for me and for that I did 2 things: 1 - Installed wheel package

pip3 install wheel

2 - I followed this thread - Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)

Aman
  • 31
  • 4
0

try to install the latest version of mysqlclient

mysqlclient==2.0.3

version 2.0.3 worked for me in python 3.9 (win)

Al Mahdi
  • 110
  • 1
  • 7