Python3.6安装MySQL-python报错:找不到config-win.h文件求助
Hey there! Let's sort out this MySQL driver issue you're facing with Python 3.6.
First off, a key point: the MySQL-python package only supports Python 2.x versions—that's the core reason your installation is failing, and the config-win.h missing error is just a side effect of it not being adapted for Python 3 environments.
Here are several reliable, Python 3.6-compatible solutions for you:
方案1:使用mysqlclient(推荐)
This is the official Python 3 fork of MySQL-python, with great compatibility and almost identical API to the original package. Install it with:
pip install mysqlclient
If you run into compilation errors (common on Windows due to missing dependencies), you can download a pre-built wheel file matching your Python 3.6 version, then install it directly:
pip install path/to/mysqlclient-xxxx-cp36-none-win_amd64.whl
方案2:使用pymysql
A pure-Python implemented MySQL driver that requires no compilation, making it highly cross-platform. Install it easily with:
pip install pymysql
If your code originally uses the MySQLdb API, just add these two lines at the start of your script to achieve seamless compatibility:
import pymysql pymysql.install_as_MySQLdb()
关于你提到的MySQL Connector
You said it's incompatible with Python 3.6? Actually, the official mysql-connector-python does support Python 3.6—you might have installed an outdated version before. Try installing a specific compatible version:
pip install mysql-connector-python==8.0.28 # This version explicitly supports Python 3.6
Also, if you're on Windows, make sure you have Visual C++ Build Tools installed (for compilation-based driver packages), or just use pre-built wheel files to avoid compilation-related errors entirely.
内容的提问来源于stack exchange,提问作者AnjuT

