1

I am trying to install mysqlclient using pip but it keeps running into an error. I have seen suggestions telling me to make sure my python version in mysqlclient is up to date. I have already done that. After pushing to mysqlclient master, i ran the install command but it gives me the following errors.

How can I fix this error?

pip install mysqlclient

Error:

(base) brijesh:~ sierra$ pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-1.4.6.tar.gz (85 kB)
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-wheel-yu73tf06
       cwd: /private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/
  Complete output (30 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.9-x86_64-3.7
  creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/compat.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
  creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
  running build_ext
  building 'MySQLdb._mysql' extension
  creating build/temp.macosx-10.9-x86_64-3.7
  creating build/temp.macosx-10.9-x86_64-3.7/MySQLdb
  gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/anaconda3/include -arch x86_64 -I/opt/anaconda3/include -arch x86_64 -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 -I/usr/local/mysql/include -I/opt/anaconda3/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.o
  xcrun: error: active developer path ("/Applications/Xcode 9.1.app/Contents/Developer") does not exist
  Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
  See `man xcode-select` for more details.
  error: command 'gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... error
    ERROR: Command errored out with exit status 1:
     command: /opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/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 /private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-record-xce3nbnm/install-record.txt --single-version-externally-managed --compile --install-headers /opt/anaconda3/include/python3.7m/mysqlclient
         cwd: /private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/
    Complete output (30 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.7
    creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/compat.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb
    creating build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.7/MySQLdb/constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.macosx-10.9-x86_64-3.7
    creating build/temp.macosx-10.9-x86_64-3.7/MySQLdb
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/anaconda3/include -arch x86_64 -I/opt/anaconda3/include -arch x86_64 -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 -I/usr/local/mysql/include -I/opt/anaconda3/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.7/MySQLdb/_mysql.o
    xcrun: error: active developer path ("/Applications/Xcode 9.1.app/Contents/Developer") does not exist
    Use `sudo xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `xcode-select --install` to install the standalone command line developer tools.
    See `man xcode-select` for more details.
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /opt/anaconda3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-install-8qoawh1_/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 /private/var/folders/pm/gmghbq8960bgdq9hk_bx25qc0000gn/T/pip-record-xce3nbnm/install-record.txt --single-version-externally-managed --compile --install-headers /opt/anaconda3/include/python3.7m/mysqlclient Check the logs for full command output.
4
  • When I experienced this it was because I had a 32 bit version of python. Try installing a 64 bit version of python?
    – Reez0
    Commented Mar 3, 2020 at 9:01
  • 1
    @Reez0 So what do I do now? Commented Mar 3, 2020 at 9:07
  • Make sure the 64 bit version of Python is on your PATH and run pip install mysqlclient. Or uninstall the 32 bit version of python entirely and then retry.
    – Reez0
    Commented Mar 3, 2020 at 9:09
  • 1
    @Reez0 How do I add a path? Commented Mar 3, 2020 at 9:20

2 Answers 2

0

You seem to be using anaconda, as your python is at /opt/anaconda3/bin/python you should therefore prefer to install using a conda command:

conda install mysqlclient

That being said, your original issue seems to be related to xcode and your error suggests to run

xcode-select --install

I am not an apple user though and am not too familiar with installing the right development tools on MacOS. If above doesn't work, you might also consider asking at http://apple.stackexchange.com

-2
sudo apt-get install libssl-dev

pip install mysqlclient

This may be a duplicate question, origin one is : Python 3.7, Failed building wheel for MySql-Python

4
  • sudo apt-get install libssl-dev Sir, this doesn't work, and I had trouble so I put the question, I didn't copy any other questions. Commented Mar 3, 2020 at 9:05
  • Sorry about that. Would you try this command : sudo apt-get install libevent-dev, and then see if it can success.
    – everfight
    Commented Mar 3, 2020 at 9:08
  • No sir this doesn't work Commented Mar 3, 2020 at 9:13
  • Sorry, I have no idea.
    – everfight
    Commented Mar 3, 2020 at 9:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.