Problem installing MySQL-Python on Mac OS 10.14.1

2019-07-28 00:18发布

问题:

I recently upgraded to Mac OS Mojave and now can't install MySQL-Python:

pip install MySQL-Python

...
clang -bundle -undefined dynamic_lookup build/temp.macosx-10.13-x86_64-2.7/_mysql.o -L/usr/local/opt/mysql-client/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.13-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

The stack trace says that the "ssl" library wasn't found. I'm not sure what that means though as I have the latest XCode and OpenSSL is installed. Any advice appreciated.

回答1:

I had the same issue on MacOS 10.14, and I was able to solve it using these steps:

Change permissions for /usr/local to allow Homebrew to create links:

sudo chown -R $(whoami) $(brew --prefix)/*

Re-install openssl now that permissions have been fixed:

brew reinstall openssl

Run these two commands to allow compilers to find openssl:

export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"

Then, try again to install MySQL-Python:

pip install MySQL-Python


回答2:

Change permissions for /usr/local to allow Homebrew to create links:

sudo chown -R $(whoami) $(brew --prefix)/*

Re-install openssl now that permissions have been fixed:

brew reinstall openssl

Run these two commands to allow compilers to find openssl:

export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"

Then, try again to install MySQL-Python:

pip install MySQL-Python

It works for Mac 10.14.2 with python2.7 /Django 1.9.8 and mysql-server 8 with mysql-clinet;