Search code examples
pythonmysql-pythonmysql-connector

MacOS: "pip install MySQL-python" returning an error: "_mysql.c:44:10: fatal error: 'my_config.h' file not found"


I have looked all over the internet including here. I have tried all the suggested solutions, but none of them worked. Here is the error message I get _mysql.c:44:10: fatal error: 'my_config.h' file not found

Could the problem come from the fact that my MySQL and Python versions are not compatible? MySql version:Ver 8.0.21 for osx10.15 on x86_64 (Homebrew) Python version:Python 2.7.16

Could that simply be it? Thanks!


Solution

  • This solution is for macOS users

    After struggling a while on this issue I finally solved it, and it was pretty simple in the end. Maybe this will help others too, because I have seen this issue around a lot during my research. There are plenty of solutions out there, that worked for some and not for others. None of them worked for me.

    Before you go into a copy/paste of commands rampage in your terminal, you might want to check your MySQL version. Because apparently MySQL only supports the MySQL-python dependency until version 5.7. So I just had to downgrade my MySQL 8 to 5.7, and then I could finally run the pip install MySQL-python command, and it worked!

    So if you have a MySQL version higher than 5.7, you might want to downgrade. To that, type in these commands in your terminal:

    brew unlink mysql

    brew install [email protected]

    Then, try mysql --version If mysql is still red, run this command:

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

    And you should finally be able to run:

    pip install MySQL-python

    This worked for me, hope it will for you!