can't install mysqlclient on mac os x mojave
Asked Answered
S

5

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/
Seay answered 2/11, 2018 at 0:14 Comment(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.Ding
@Ding Im using virtualenvironment. I have lssl installed as well.Seay
@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.Jenaejenda
Please avoid creating incorrect tags: Mac OSX was renamed to macOS more than two years ago.Valletta
M
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"
Mullein answered 7/11, 2018 at 10:37 Comment(1)
The information from brew info openssl is the key.Roundfaced
S
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.

Sociable answered 8/1, 2019 at 5:22 Comment(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.Piperidine
Working also for me on Mac OS High SierraBingen
S
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
Seay answered 7/11, 2018 at 23:12 Comment(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.Allhallows
Using PyCharm to create the virtual environment, rather than commandline, resulted in an environment where mysqlclient installed cleanly!Allhallows
I have been searching all over for this! THANK YOU! If you're on mojave and trying to install mysqlclient look no further!Pollute
A
1

Try using:-

pip install mysqlclient=1.4.2.post1

Arsine answered 18/8, 2019 at 13:6 Comment(0)
S
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.

Servomechanism answered 30/9, 2023 at 19:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.