美文网首页
Python3.7安装mysqlclient出错

Python3.7安装mysqlclient出错

作者: 冷风凝霜 | 来源:发表于2020-03-15 20:35 被阅读0次

本机的python从2.7升级到3.7后,mysqldb这个包就失效了,一直无法使用,由于用的少,也就没去管。今天答应帮朋友个小忙要用到mysql,所以打算把这个搁置了很久的小问题解决掉,以便后面可以继续用。

首先,其实python升级到3.7之后,原来的mysqldb已经不支持了,需要换成mysqlclient(地址戳我

Mac系统安装步骤:

1. brew install mysql-client

2. pip install mysqlclient

以上步骤很简单,但在pip install mysqlclient的时候报错如下:

ERROR: Command errored out with exit status 1:

     command: /Users/Allen/Documents/workSpace/PythonPack/ventpy3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nm/yd1zh7p54xb5t9wsb73j846w0000gp/T/pip-install-pf8mmrsv/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/nm/yd1zh7p54xb5t9wsb73j846w0000gp/T/pip-install-pf8mmrsv/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/var/folders/nm/yd1zh7p54xb5t9wsb73j846w0000gp/T/pip-record-9bmrkgmw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/Allen/Documents/workSpace/PythonPack/ventpy3/include/site/python3.7/mysqlclient

         cwd: /private/var/folders/nm/yd1zh7p54xb5t9wsb73j846w0000gp/T/pip-install-pf8mmrsv/mysqlclient/

    Complete output (32 lines):

    /usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/distutils/dist.py:274: UserWarning: Unknown distribution option: 'long_description_content_type'

      warnings.warn(msg)

    running install

    running build

    running build_py

    creating build

    creating build/lib.macosx-10.14-x86_64-3.7

    creating build/lib.macosx-10.14-x86_64-3.7/MySQLdb

    copying MySQLdb/__init__.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb

    copying MySQLdb/_exceptions.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb

    copying MySQLdb/compat.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb

    copying MySQLdb/connections.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb

    copying MySQLdb/converters.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb

    copying MySQLdb/cursors.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb

    copying MySQLdb/release.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb

    copying MySQLdb/times.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb

    creating build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants

    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants

    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants

    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants

    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants

    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants

    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants

    running build_ext

    building 'MySQLdb._mysql' extension

    creating build/temp.macosx-10.14-x86_64-3.7

    creating build/temp.macosx-10.14-x86_64-3.7/MySQLdb

    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/opt/mysql-client/include -Dversion_info=(1,4,6,'final',0) -D__version__=1.4.6 -I/usr/local/Cellar/mysql/8.0.18/include/mysql -I/Users/Allen/Documents/workSpace/PythonPack/ventpy3/include -I/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.macosx-10.14-x86_64-3.7/MySQLdb/_mysql.o

    clang -bundle -undefined dynamic_lookup -L/usr/local/opt/mysql-client/lib -I/usr/local/opt/mysql-client/include build/temp.macosx-10.14-x86_64-3.7/MySQLdb/_mysql.o -L/usr/local/Cellar/mysql/8.0.18/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-x86_64-3.7/MySQLdb/_mysql.cpython-37m-darwin.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

    ----------------------------------------

ERROR: Command errored out with exit status 1: /Users/Allen/Documents/workSpace/PythonPack/ventpy3/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/nm/yd1zh7p54xb5t9wsb73j846w0000gp/T/pip-install-pf8mmrsv/mysqlclient/setup.py'"'"'; __file__='"'"'/private/var/folders/nm/yd1zh7p54xb5t9wsb73j846w0000gp/T/pip-install-pf8mmrsv/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/var/folders/nm/yd1zh7p54xb5t9wsb73j846w0000gp/T/pip-record-9bmrkgmw/install-record.txt --single-version-externally-managed --compile --install-headers /Users/Allen/Documents/workSpace/PythonPack/ventpy3/include/site/python3.7/mysqlclient Check the logs for full command output.

最终发现,其实是openssl没有指明配置路径,解决方法如下:

export LDFLAGS="-L/usr/local/opt/openssl/lib $LDFLAGS"

export CPPFLAGS="-I/usr/local/opt/openssl/include $CPPFLAGS"

完成后再执行pip install mysqlclient即可!

相关文章

网友评论

      本文标题:Python3.7安装mysqlclient出错

      本文链接:https://www.haomeiwen.com/subject/frdbehtx.html