Error installing mysql-python: library not found f

2019-01-23 16:41发布

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:

  • libressl
  • openssl
  • openssl@1.1
  • mysql

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

The OS is MacOS Sierra.

Can anyone help? Thanks!

8条回答
【Aperson】
2楼-- · 2019-01-23 17:10

You can set ssl library path explicitly.

LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient
查看更多
Root(大扎)
3楼-- · 2019-01-23 17:13

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.

查看更多
在下西门庆
4楼-- · 2019-01-23 17:17

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!

查看更多
\"骚年 ilove
5楼-- · 2019-01-23 17:19

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

查看更多
6楼-- · 2019-01-23 17:23

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!)

查看更多
孤傲高冷的网名
7楼-- · 2019-01-23 17:23

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

I found that running brew info ssl 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).

查看更多
登录 后发表回答