You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MacBook Pro下Python连接MySQL时pip install mysql报错求助

Fixing ModuleNotFoundError: No module named 'ConfigParser' when installing MySQL for Python on MacBook Pro

Hey there, let's break down what's going on and fix this issue quickly:

Why you're seeing this error

The mysql package you're trying to install (pip install mysql) is the old MySQL-python library, built exclusively for Python 2. In Python 3, the module name changed from ConfigParser to configparser (lowercase), so this outdated package throws an error when trying to run on your Python 3 environment.

Solutions to get connected to MySQL

Here are the two most reliable ways to set up a Python 3-compatible MySQL connection on your MacBook Pro:

1. Use mysqlclient (Recommended, drop-in replacement for MySQL-python)

This is the official Python 3 fork of MySQL-python, and it works seamlessly with most code that expects the old library.

  • First, install the required system dependencies using Homebrew:
    brew install mysql-client
    
  • If you get a "mysql_config not found" error during installation, add the mysql-client bin directory to your PATH temporarily:
    export PATH="/usr/local/opt/mysql-client/bin:$PATH"
    
  • Now install the Python package:
    pip install mysqlclient
    
  • Note: If you hit compilation errors, make sure you have Xcode Command Line Tools installed:
    xcode-select --install
    

2. Use pymysql (Pure-Python, no compilation needed)

If you prefer a library that doesn't require compiling system-level code, pymysql is a great alternative.

  • Install the package:
    pip install pymysql
    
  • If your code was written to use the old MySQLdb module (from MySQL-python), add this at the top of your script to make pymysql act as a drop-in replacement:
    import pymysql
    pymysql.install_as_MySQLdb()
    

Important Note

Never use pip install mysql for Python 3 projects — that package is abandoned and incompatible with modern Python versions. Stick to either mysqlclient or pymysql instead.

内容的提问来源于stack exchange,提问作者tmcdo13

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 09:27:35