Macos编译mysql-python报错 ld: library not found for -lssl

首先,我通过: 

pip install mysql-python

然后报错

_mysql.c:1504:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                  len = strlen(buf);
                                      ~ ^~~~~~~~~~~
  _mysql.c:1506:11: warning: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Wshorten-64-to-32]
                                  len = strlen(buf);
                                      ~ ^~~~~~~~~~~
  15 warnings generated.
  cc -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.14-intel-2.7/_mysql.o -L/usr/local/Cellar/[email protected]/5.6.43/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-intel-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 'cc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for mysql-python

其中,主要报错:

ld: library not found for -lssl
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  error: command 'cc' failed with exit status 1

原因分析:

安装过程中,无法找到openssl文件

由于苹果公司已经放弃openssl加密转而使用自家的加密方式,导致mac上面是没有oepnssl的,所以需要

# 安装openssl
brew install openssl
# 如果已经安装
brew upgrade openssl
# 如果还不行
xcode-select --install

如果还不行(例如我),那么直接在pip的时候链接brew的openssl,记得用上不使用缓存模式

env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip --no-cache install mysql-python==1.2.5

ok!

结果如下:

Collecting mysql-python==1.2.5
  Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
     |████████████████████████████████| 112kB 26kB/s 
Building wheels for collected packages: mysql-python
  Building wheel for mysql-python (setup.py) ... done
  Created wheel for mysql-python: filename=MySQL_python-1.2.5-cp27-cp27m-macosx_10_14_intel.whl size=43965 sha256=a67ff16500c2a8a2690ffae0f5a3be3c3271ec2d273c258bded1ea38efc6d6d8
  Stored in directory: /private/tmp/pip-ephem-wheel-cache-enjEof/wheels/07/d2/5f/314860e4cb53a44bf0ee0d051d4b34465e4b4fbe9de6d42f42
Successfully built mysql-python
Installing collected packages: mysql-python
Successfully installed mysql-python-1.2.5

 

你可能感兴趣的:(Macos编译mysql-python报错 ld: library not found for -lssl)