Error installing mysql-python: library not found for -lssl
Asked Answered
V

11

28

I'm having trouble installing mysql-python. Created a new virtualenv and when installing mysql-python... here's 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 have installed:

Already tried to brew link but brew refuses to do so.

The OS is MacOS Sierra.

Can anyone help? Thanks!

Vashtivashtia answered 14/11, 2016 at 11:21 Comment(0)
V
13

Solved it with these 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 https://mcmap.net/q/196919/-installing-mysql-python-on-mac-os-x

Not sure if this is the right way, but this is how I managed to solve it.

Vashtivashtia answered 14/11, 2016 at 16:4 Comment(0)
M
43

You can set ssl library path explicitly.

LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient
Melodymeloid answered 23/10, 2017 at 11:57 Comment(4)
The library installed. However, it fails to run with segmentation fault 11Woodsy
Solved my problem.Rimmer
Solved my problem as well.Dishwater
For more general (if installing openssl through brew): LDFLAGS="-L$(brew --prefix openssl)/lib" pip install mysqlclientTaggart
T
25

I tried updating Xcode's CLT, uninstalling mysql, checking mysql_config, etc., but had no luck.

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 those two commands, followed by pip install, worked for me (in my case when installing mysqlclient).

Translate answered 6/12, 2018 at 14:39 Comment(3)
Thanks, that helped but one should run "brew info openssl" and not "brew info ssl" and then I run all "export" commands which helped me successfully run "pip3 install mysqlclient"Triable
@Triable Correct, thanks for pointing that out, I've updated the answer.Translate
saved a day. @TranslateUnforgettable
V
13

Solved it with these 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 https://mcmap.net/q/196919/-installing-mysql-python-on-mac-os-x

Not sure if this is the right way, but this is how I managed to solve it.

Vashtivashtia answered 14/11, 2016 at 16:4 Comment(0)
G
11

I'm able to 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"
Grandaunt answered 1/3, 2019 at 16:44 Comment(1)
This worked for me . Brew states - openssl is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL.Dressing
X
8

I was finally able to fix it by

xcode-select --install

I was sure I had already done that... but obviously I hadn't. Definitely worth a shot!

Xever answered 14/3, 2017 at 11:44 Comment(0)
C
3

For me on mac, running this command solved the issue

LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient

Actually we need to set ssl library path to get this issue fixed.

Carbine answered 27/11, 2019 at 16:31 Comment(2)
Strangely enough this worked for me. I have no idea why but it worked.Dishwater
Hi @hafiz-siddiq, there's another answer like yours https://mcmap.net/q/196080/-error-installing-mysql-python-library-not-found-for-lssl, this doesn't add value.Hiragana
E
2

Worked for me by doing this

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

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

Epithet answered 7/6, 2017 at 14:16 Comment(1)
This also fixes the error I received ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output. This fixes the issue for this substitution for the last line pip3 install mysqlclientAgle
S
2

If you want to install mysql-python, I suggest you to install mysqlclient instead. The authors of these two modules are the same. By far, the authors all turn to keep maintaining mysqlclient. mysqlclient supports both Python 2 and Python 3. And you can use the same codes like 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 there is an error before pip install mysqlclient. Please fix it according to methane's answer. And run pip install mysqlclient again.

Strategist answered 17/7, 2017 at 6:31 Comment(0)
E
1

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

Excisable answered 21/1, 2017 at 0:28 Comment(1)
This works too but, it also messes with me that there are 3 ways you can install mysql on your mac. brew pip and also the dmg file. and if you have more than just one, it becomes a nightmare with odd errors or breaking the DMG install by using pip or brew.Agle
E
1

For those of you who are installing MySQL v5.7 with Brew

Uninstall mysql-connector-c

$ brew uninstall mysql-connector-c

Install specific version, very likely you need to uninstall other installed versions

$ brew install [email protected]

You will need to add it to the PATH, since this is 'keg-only' formulae, this is printed after it is installed

$ echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc

Replace ~/.zshrc with the appropriate file.

Install mysql-connector-c

$ brew install mysql-connector-c

Check it is installed properly

$ which mysql
# /usr/local/opt/[email protected]/bin/mysql

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

Now install mysqlclient

$ pip install mysqlclient
Eleonoreleonora answered 4/1, 2019 at 19:2 Comment(0)
W
1

For those on MacOS (me on Ventura) using pip requirements.txt file, universal solution is:

LDFLAGS="-L$(brew --prefix openssl)/lib" pip install -r requirements.txt

where requirements.txt file contains mysqlclient, e.g:

asgiref==3.7.2
click==8.1.6
Django==4.2.3
mysqlclient==2.2.0
Pillow==10.0.0
sqlparse==0.4.4
svgwrite==1.4.3

To make life easier, you can use pip-compile requirements.in command, which uses in file of flexible content like this:

Django>=4.2,<5.0
mysqlclient>=2.2,<3.0

and run

pip-compile

which compiles requirements.txt from requirements.in, pyproject.toml, setup.cfg, or setup.py specs.

And finally do the LDFLAGS="-L$(brew --prefix openssl)/lib" pip install -r requirements.txt command.

One more note, later, if you need to upgrade packages, just run:

pip-compile -U

Good luck!

Wolof answered 28/7, 2023 at 21:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.