7

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/
4
  • More to the point, it looks like you don't have SSL libraries available. I don't use macOS so I'm not sure how to install them there.
    – Chris
    Nov 2, 2018 at 0:16
  • @Chris Im using virtualenvironment. I have lssl installed as well.
    – Atma
    Nov 2, 2018 at 0:17
  • @Chris: In macOS the permissions are setup this way by default. Without using sudo then you'd likely need to setup a wheel user in order install things without it.
    – l'L'l
    Nov 2, 2018 at 0:21
  • Please avoid creating incorrect tags: Mac OSX was renamed to macOS more than two years ago.
    – Cœur
    Nov 2, 2018 at 6:40

5 Answers 5

24

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"
1
  • 1
    The information from brew info openssl is the key.
    – Rockallite
    Jan 30, 2019 at 3:35
11
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.

2
  • No idea what it did but it solved it for me. Could install mysqlclient on the computer but not in a virtual environment. That did it. Jun 19, 2019 at 13:51
  • Working also for me on Mac OS High Sierra
    – dannydedog
    Mar 30, 2020 at 14:54
4

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
3
  • My Mojave doesn't have a Packages folder, so this didn't work for me. I had mysqlclient installed in a virtual environment, then deleted the environment to test my requirements file. The second time i installed the library, it failed. Nov 27, 2018 at 14:00
  • Using PyCharm to create the virtual environment, rather than commandline, resulted in an environment where mysqlclient installed cleanly! Nov 27, 2018 at 14:01
  • I have been searching all over for this! THANK YOU! If you're on mojave and trying to install mysqlclient look no further!
    – Mickey Sly
    Apr 2, 2019 at 18:52
1

Try using:-

pip install mysqlclient=1.4.2.post1

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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