Mac pipenv install mysqlclient failed解决方案

原文地址

问题

当执行

pipenv install mysqlclient

出现如下错误

An error occurred while installing mysqlclient==1.3.13!
...
...
...
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
...
...
...

解决方案

  1. 首先确保你的mac上安装了mysql
brew install/upgrade/reinstall mysql
  1. 在terminal下输入下面内容
brew info openssl
openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.

If you need to have openssl first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile

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"

For pkg-config to find openssl you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
  1. 根据提示在.bash_profile中添加
export PATH="/usr/local/opt/openssl/bin:$PATH"

在这里插入图片描述
然后执行

source ~/.bash_profile
  1. 在terminal中执行
  export LDFLAGS="-L/usr/local/opt/openssl/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl/include"

最后安装成功

$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"
$ pipenv install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/4d/38/c5f8bac9c50f3042c8f05615f84206f77f03db79781db841898fde1bb284/mysqlclient-1.4.4.tar.gz
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... done
  Created wheel for mysqlclient: filename=mysqlclient-1.4.4-cp37-cp37m-macosx_10_14_x86_64.whl size=55994 sha256=a0b1b9a250b60d438ca74ba20c15ac210fccb4a39ebe68aa3c62470a8ca70713
  Stored in directory: /Users/rhm/Library/Caches/pip/wheels/a0/04/57/031b9b01df38999df7dc7f4ee998a98ecdbd2d781f73e3ffbf
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-1.4.4

你可能感兴趣的:(python)