Mac上安裝mysqlclient的報(bào)錯(cuò)

執(zhí)行

sudo pip install mysqlclient

后一直報(bào)錯(cuò),完整信息如下:

 ERROR: Complete output from command /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 -u -c 'import setuptools, tokenize;__file__='"'"'/private/tmp/pip-install-ky29wysn/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/tmp/pip-record-k_myj461/install-record.txt --single-version-externally-managed --compile:
    ERROR: running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.6-intel-3.6
    creating build/lib.macosx-10.6-intel-3.6/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb
    copying MySQLdb/compat.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb
    creating build/lib.macosx-10.6-intel-3.6/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.6-intel-3.6/MySQLdb/constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.macosx-10.6-intel-3.6
    creating build/temp.macosx-10.6-intel-3.6/MySQLdb
    /usr/bin/clang -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -Dversion_info=(1,4,2,'post',1) -D__version__=1.4.2.post1 -I/usr/local/Cellar/mysql-connector-c/6.1.11/include -I/Library/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c MySQLdb/_mysql.c -o build/temp.macosx-10.6-intel-3.6/MySQLdb/_mysql.o
    /usr/bin/clang -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g build/temp.macosx-10.6-intel-3.6/MySQLdb/_mysql.o -L/usr/local/Cellar/mysql-connector-c/6.1.11/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.6-intel-3.6/MySQLdb/_mysql.cpython-36m-darwin.so
    ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/clang' failed with exit status 1
    ----------------------------------------
ERROR: Command "/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 -u -c 'import setuptools, tokenize;__file__='"'"'/private/tmp/pip-install-ky29wysn/mysqlclient/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/tmp/pip-record-k_myj461/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/tmp/pip-install-ky29wysn/mysqlclient/

經(jīng)過一番查找,參考這篇文章解決了問題,感謝博主。
回到正題

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

這3句才是重點(diǎn),意思是使用openssl的一些指令的時(shí)候報(bào)錯(cuò),應(yīng)該是openssl的一些變量需要先聲明一下,具體怎么操作:用你的homebrew來一下

brew info openssl

然后出現(xiàn)

openssl: stable 1.0.2s (bottled) [keg-only]
SSL/TLS cryptography library
https://openssl.org/
/usr/local/Cellar/openssl/1.0.2s (1,795 files, 12.0MB)
  Poured from bottle on 2019-06-24 at 14:48:24
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openssl.rb
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
......(此處省略一大段)
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"

這就提示你執(zhí)行最后的兩條指令,把兩個(gè)變量export一下(‘echo $變量名’檢測(cè)export的結(jié)果),此處建議不要換終端或者重啟終端,因?yàn)檫@兩個(gè)剛export的變量是臨時(shí)的,然后緊接著就

pip3 install mysqlclient  

一切OK

Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.4.2.post1

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容