Error installing mysql-python: library not found for -lssl

I am having trouble installing mysql-python. Created a new virtualenv and when installing mysql-python ... here is the error message:

(env)$ pip install mysql-python Collecting mysql-python ... clang -bundle -undefined dynamic_lookup -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk build/temp.macosx-10.12-x86_64-2.7/_mysql.o -L/usr /local/Cellar/mysql/5.7.16/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.12-x86_64-2.7/_mysql.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 

Using homebrew, I installed:

  • libressl
  • Openssl
  • openssl@1.1
  • MySQL

Already tried brew link , but brew refuses to do this.

OS - MacOS Sierra.

Can anyone help? Thanks!

+17
pip homebrew mysql-python virtualenv
source share
9 answers

Solved this with the following steps:

 brew uninstall mysql brew install mysql-connector-c pip install mysql-python brew unlink mysql-connector-c brew install mysql 

Found the answer here fooobar.com/questions/248891 / ...

Iโ€™m not sure if this is the right way, but thatโ€™s how I managed to solve it.

+12
source share

You can explicitly specify the ssl library path.

 LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient 
+23
source share

Finally, I was able to fix it

xcode-select --install

I was sure I already did this ... but obviously I did not. Definitely worth a shot!

+8
source share

I tried updating Xcode CLT, removing mysql , checking mysql_config, etc., but to no avail.

I found that running brew info openssl shows:

 ... 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" ... 

Running these two commands followed by pip install worked for me (in my case, when installing mysqlclient ).

+7
source share

I can fix the error by running:

 pip install -r requirements.txt --global-option=build_ext --global-option="-I/usr/local/opt/openssl/include" --global-option="-L/usr/local/opt/openssl/lib" 
+5
source share

Worked for me doing this

 $ brew uninstall mysql $ brew install mysql-connector-c $ brew unlink mysql-connector-c $ brew install mysql $ pip install mysql-python 

This is a slightly modified version of the recipe above (note: pip install at the end!)

+2
source share

If you want to install mysql-python , I suggest you install mysqlclient . The authors of these two modules are the same. Of course, authors all continue to support mysqlclient . mysqlclient supports both Python 2 and Python 3. And you can use the same codes as mysql-python . Blew is my installation solution for you.

 $ brew info openssl $ brew unlink mysql-connector-c $ brew install mysql $ brew link --overwrite mysql-connector-c $ pip install mysqlclient 

If before pip install mysqlclient there is an error. Please correct it according to metane answer . And run pip install mysqlclient .

+2
source share

Or download and install .dmg from the dev dev website: https://dev.mysql.com/downloads/file/?id=467834

+1
source share

For those of you who install MySQL v5.7 with Brew

Remove mysql-connector-c

 $ brew uninstall mysql-connector-c 

Install a specific version, most likely you need to remove other installed versions

 $ brew install mysql@5.7 

You will need to add it to PATH , as these are โ€œbarrel-onlyโ€ formulas, they print after installation

 $ echo 'export PATH="/usr/local/opt/ mysql@5.7 /bin:$PATH"' >> ~/.zshrc 

Replace ~/.zshrc with the appropriate file.

Install mysql-connector-c

 $ brew install mysql-connector-c 

Check if it is installed correctly

 $ which mysql # /usr/local/opt/ mysql@5.7 /bin/mysql $ mysql_config # Usage: /usr/local/opt/ mysql@5.7 /bin/mysql_config [OPTIONS] Compiler: Clang 10.0.0.10001145 Options: --cflags [-I/usr/local/opt/ mysql@5.7 /include/mysql ] --cxxflags [-I/usr/local/opt/ mysql@5.7 /include/mysql ] --include [-I/usr/local/opt/ mysql@5.7 /include/mysql] --libs [-L/usr/local/opt/ mysql@5.7 /lib -lmysqlclient -lssl -lcrypto] --libs_r [-L/usr/local/opt/ mysql@5.7 /lib -lmysqlclient -lssl -lcrypto] --plugindir [/usr/local/opt/ mysql@5.7 /lib/plugin] --socket [/tmp/mysql.sock] --port [0] --version [5.7.24] --libmysqld-libs [-L/usr/local/opt/ mysql@5.7 /lib -lmysqld -lssl -lcrypto] --variable=VAR VAR is one of: pkgincludedir [/usr/local/opt/ mysql@5.7 /include/mysql] pkglibdir [/usr/local/opt/ mysql@5.7 /lib] plugindir [/usr/local/opt/ mysql@5.7 /lib/plugin] 

Now install mysqlclient

 $ pip install mysqlclient 
0
source share

All Articles