欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

macos 安装MySQLdb:pip install MySQL-python

程序员文章站 2024-02-10 12:59:28
...

1.第一步安装 mysql connector:

brew install mysql-connector-c

2.之后需要确认 mysql_config文件里面的几行配置,可以先用下面的路径查看是否存在该文件:

vim /usr/local/bin/mysql_config

如果上述路径下不存在mysql_config文件,则应该可以在下面的路径下找到:

/usr/local/Cellar/mysql-connector-c/6.1.11/bin/

找到上述文件后,修改下面两行:

  # Create options 
  libs="-L$pkglibdir"
  libs="$libs -l "
  改为下面两行配置:
  # Create options 
  libs="-L$pkglibdir"
  libs="$libs -lmysqlclient -lssl -lcrypto"
3.执行下面指令,配置openssl:

brew info openssl

it would tell what’s needed

 For compilers to find this software you may need to set:
      LDFLAGS:  -L/usr/local/opt/openssl/lib
      CPPFLAGS: -I/usr/local/opt/openssl/include
  For pkg-config to find this software you may need to set:
      PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

执行一下上述指令返回的几个指令:如:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"

4.安装 MySQL

pip2.7 install MySQL-python --user

5.测试 MySQL是否安装成功:

python -c "import MySQLdb"

相关标签: MySQLdb