can't install mysqlclient on mac os x mojave

8.8k Views Asked by At

I'm trying to install mysqlclient on mac os x mojave:

sudo pip3 install mysqlclient

I get the following error:

clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 -I/usr/local/Cellar/mysql/8.0.12/include/mysql -I/usr/local/Cellar/python3/3.6.4/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c _mysql.c -o build/temp.macosx-10.13-x86_64-3.6/_mysql.o
    clang -bundle -undefined dynamic_lookup build/temp.macosx-10.13-x86_64-3.6/_mysql.o -L/usr/local/Cellar/mysql/8.0.12/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.13-x86_64-3.6/_mysql.cpython-36m-darwin.so
    ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command 'clang' failed with exit status 1

    ----------------------------------------
Command "/Users//Development/apps/hid_ve/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-1mo7e_ok/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/tmp/pip-record-9bwluwz6/install-record.txt --single-version-externally-managed --compile --install-headers /Users//Development/apps/hid_ve/bin/../include/site/python3.6/mysqlclient" failed with error code 1 in /private/tmp/pip-install-1mo7e_ok/mysqlclient/
5

There are 5 best solutions below

1
On

I got the same error as you after upgrading to mojave. After some digging, the following steps help:

brew info openssl

The output is useful. If you are using bash or zsh, the message is:

For compilers to find openssl you may need to set:

export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"

After execute the above commands, everything is back normal.

Additionally if you are using fish. The message is:

For compilers to find openssl you may need to set:

set -gx LDFLAGS "-L/usr/local/opt/openssl/lib"
set -gx CPPFLAGS "-I/usr/local/opt/openssl/include"
3
On

I solved the issue with the following:

  1. Go to folder:

/Library/Developer/CommandLineTools/Packages

  1. Click on and install: macOS_SDK_headers_for_macOS_10.14.pkg
  2. Delete your virtual environment
  3. Create a new virtual environment.
  4. Install mysqlclient: pip3 install mysqlclient
0
On

Try using:-

pip install mysqlclient=1.4.2.post1

2
On
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

from ld: library not found for -lssl after Mac OS Sierra upgrade

It works for me.

0
On

I was getting a error when I run the code "pip install mysqlclient" inside a virtualenv. Then I run "pip install mysqlclient==2.1.1" and it works. I'm using mac OS Mojave on a 2014 macbook pro.