Mac OS 安装mysqlcliet 失败问题解决

如果你不相信努力和时光,那么成果就会是第一个选择辜负你的。不要去否定你自己的过去,也不要用你的过去牵扯你现在的努力和对未来的展望。不是因为拥有希望你才去努力,而是去努力了,你才有可能看到希望的光芒。Mac OS 安装mysqlcliet 失败问题解决,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

简单记录 Mac OS pip 安装mysqlclient报错处理过程
系统:
Mac OS 安装mysqlcliet 失败问题解决
python: Python 3.8.2 虚拟环境

直接安装 mysqlclient 会报错

Using cached https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-bz44wlso/mysqlclient/setup.py", line 16, in <module>
        metadata, options = get_config()
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-bz44wlso/mysqlclient/setup_posix.py", line 51, in get_config
        libs = mysql_config("libs")
      File "/private/var/folders/6c/jdnqnjsx48d8qj0kwn751c580000gn/T/pip-install-bz44wlso/mysqlclient/setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    OSError: mysql_config not found

报错的原因是:mysql_config not found

在网上找了一圈,解决办法:

brew install mysql

然后分步走:

  1. 查找mysql_config文件夹位置sudo find / -name mysql_config,一般在/usr/local/Cellar/mysql/8.0.27/bin/mysql_config这个路径下
  2. 将mysql_config链接到/usr/local/bin目录下 ln -s /usr/local/Cellar/mysql/8.0.27/bin/mysql_config /usr/local/bin/mysql_config

做完这两步,就可以在终端里打印出mysql_config。输入mysql_config --version,能够输出

mysql_config -version
Usage: /usr/local/bin/mysql_config [OPTIONS]
Compiler: AppleClang 12.0.0.12000032
Options:
        --cflags         [-I/usr/local/Cellar/mysql/8.0.27/include/mysql ]
        --cxxflags       [-I/usr/local/Cellar/mysql/8.0.27/include/mysql ]
        --include        [-I/usr/local/Cellar/mysql/8.0.27/include/mysql]
        --libs           [-L/usr/local/Cellar/mysql/8.0.27/lib -lmysqlclient -lz -lzstd -lssl -lcrypto -lresolv]
        --libs_r         [-L/usr/local/Cellar/mysql/8.0.27/lib -lmysqlclient -lz -lzstd -lssl -lcrypto -lresolv]
        --plugindir      [/usr/local/Cellar/mysql/8.0.27/lib/plugin]
        --socket         [/tmp/mysql.sock]
        --port           [0]
        --version        [8.0.27]
        --variable=VAR   VAR is one of:
                pkgincludedir [/usr/local/Cellar/mysql/8.0.27/include/mysql]
                pkglibdir     [/usr/local/Cellar/mysql/8.0.27/lib]
                plugindir     [/usr/local/Cellar/mysql/8.0.27/lib/plugin]

这时安装还会报错,如下:

In file included from MySQLdb/_mysql.c:29:
    In file included from /usr/local/Cellar/mysql/8.0.27/include/mysql/mysql.h:45:
    In file included from /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include/stdint.h:52:
    In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/stdint.h:52:
    In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/_types.h:32:
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/sys/cdefs.h:807:2: error: Unsupported architecture
    #error Unsupported architecture

原因是 架构不支持。痛苦的尝试了一段时间后,找个一个解决办法,声明架构

export ARCHFLAGS="-arch x86_64"

安装成功:

(dev) ➜  bin pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.1.0.tar.gz (87 kB)
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
  Building wheel for mysqlclient (setup.py) ... done
  Created wheel for mysqlclient: filename=mysqlclient-2.1.0-cp38-cp38-macosx_10_14_x86_64.whl size=56114 sha256=4a7b05f15f6983798e57dddcee8f07a8e28e96f15f19a2800b2e9a3f657dc07e
  Stored in directory: /Users/lijinkui/Library/Caches/pip/wheels/61/e7/42/9d56347e42d7ce19397c0ca050c6bef56640e18be7021ac189
Successfully built mysqlclient
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.0

参考链接:
https://www.jianshu.com/p/6411c14ce3f1
https://www.cnblogs.com/xwxz/p/15248092.html

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/194207.html

(0)
小半的头像小半

相关推荐

极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!