MacOS上mysqlclient的安装

MacOS10.14.2,python3.6,安装mysqlclient报如下错误

$ sudo python3 -m pip install mysqlclient
Collecting mysqlclient
  Downloading https://files.pythonhosted.org/packages/f4/f1/3bb6f64ca7a429729413e6556b7ba5976df06019a5245a43d36032f1061e/mysqlclient-1.4.2.post1.tar.gz (85kB)
    100% |████████████████████████████████| 92kB 7.3kB/s 
    Complete output from command python setup.py egg_info:
    /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "", line 1, in 
      File "/private/tmp/pip-install-t8rcdw_s/mysqlclient/setup.py", line 16, in 
        metadata, options = get_config()
      File "/private/tmp/pip-install-t8rcdw_s/mysqlclient/setup_posix.py", line 51, in get_config
        libs = mysql_config("libs")
      File "/private/tmp/pip-install-t8rcdw_s/mysqlclient/setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    OSError: mysql_config not found
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/tmp/pip-install-t8rcdw_s/mysqlclient/

解决办法
我是先按照这两个博客做了一遍,结果还是不行
https://blog.csdn.net/feilzhang/article/details/80787748
https://www.jianshu.com/p/80f3f07f834c
后来我在.bash_profile文件中添加了如下这行:

export PATH=$PATH:/usr/local/mysql/bin

即mysql文件中mysql_config文件的路径,然后再在python虚拟环境中pip install mysqlclient时,就安装成功了,至于与上述两个博文中所写的内容是否有关,没有在深一步探讨,下次再遇见这个问题时再回来写一写。

你可能感兴趣的:(MacOS上mysqlclient的安装)