在macOS中出现_mysql.c:44:10: fatal error: 'my_config.h' file not found报错的解决方案&成功安装的方法介绍
博主使用的是mac自带的python2.7,在尝试直接sudo easy_install mysql-python失败后,又下载压缩包自行安装mysql-python时,出现了如题的错误,困扰了很久终于解决,下面介绍博主安装过程所遇到的几个问题和解决方法:
-
首先需要下载mysql-python安装包(下载地址 https://pypi.org/project/MySQL-python/#files ),解压后进入目录找到site.cfg文件,用编辑器打开,将#mysql_config = /usr/local/bin/mysql_config这一行的注释去掉,然后把路径更改为自己的安装路径,如mysql_config = /usr/local/mysql/bin/mysql_config。
-
第二步需要检查是否安装了gcc编译器套件,可以通过执行which gcc查看,若返回/usr/bin/gcc或类似内容,即证明已安装。(如果没有安装,需自行install gcc和其对应的python-devel环境)。
-
接下来在解压后的文件夹目录下依次执行
sudo python setup.py clean
sudo python setup.py build
sudo python setup.py install
其中在build时出现了_mysql.c:44:10: fatal error: ‘my_config.h’ file not found 错误,意为缺少MySQL的头文件。此时需要安装mysq-connector-c,执行brew install mysql-connector-c,在执行brew安装命令时可能会出现权限不够的问题,此时可执行sudo chown -R $(whoami) /usr/local/var/homebrew来增加权限。
(若未安装homebrew,可参考 https://www.geek-share.com/detail/2624593340.html )。 -
在安装成功后(如下图),可以运行python,进入命令行import MySQLdb进行尝试。
此时可能会出现类似于ImportError: dlopen(/Users/qtvspa/Library/Caches/Python-Eggs/MySQL_python-1.2.5-py2.7-macosx-10.13-intel.egg-tmp/_mysql.so, 2): Library not loaded: libcrypto.1.0.0.dylib的报错,
这是因为python没有在默认的目标文件夹内找到导包所需的镜像文件,因此我们需要将镜像文件拷贝到目标文件夹中。如果出现多个镜像包都无法导入的情况,需要一个一个分别拷贝。执行sudo ln -s /usr/local/mysql/lib/libssl.1.0.0.dylib /usr/lib/libssl.1.0.0.dylib即可,而后再进行MySQLdb的导入就没有问题啦。
相关参考
[1]: https://stackoverflow.com/questions/7475223/mysql-config-not-found-when-installing-mysqldb-python-interface/33928783#33928783
[2]: https://www.sunnyos.com/article-show-38.html
[3]: https://www.geek-share.com/detail/2568746000.html
- _mysql.c:44:10: fatal error: 'my_config.h' file not found
- 【解决方法】macOS 安装Resin失败:fatal error: 'openssl/ssl.h' file not found
- python安装软件出现错误 fatal error: 'libxml/xmlversion.h' file not found
- mac编译openssl扩展报错 openssl.c:44:10: fatal error: 'openssl/evp.h' file not found
- mac安装protobuf2.4.1时报错./include/gtest/internal/gtest-port.h:428:10: fatal error: 'tr1/tuple' file not found和google/protobuf/message.cc:175:16: error: implicit instantiation of undefined template
- mac配置libevet出现bufferevent_openssl.c:66:10: fatal error: 'openssl/bio.h' file not found
- Centos7 Minni 安装 执行ifconfig命令出现 -bash ifconfig command not found 的解决方法
- Scrapy安装过程中出现“'libxml/xmlversion.h' file not found“报错的处理方法
- Android移动开发-AndroidStudio调试安装时出现“Error running app: Default Activity Not Found”报错的解决方案
- 【mysql】FATAL ERROR: Could not find ./bin/my_print_defaults 解决方法
- lnn.c:4:9: fatal error: 'nanomsg/nn.h' file not found, torch nn安装错误解决办法
- ERROR! MySQL server PID file could not be found!的解决方法
- 使用 EasyBCD 安装Ubuntu 14.04 Error 15: file not found错误的解决方法
- 解决MySQL安装重装时出现could not start the service mysql error:0问题的方法
- Install libevent bufferevent_openssl.c:60:10: fatal error: 'openssl/bio.h' file not found
- [python]"python[error] mysql_config not found"错误解决方法
- PyCharm出现错误,Fatal Python error: Py_Initialize: unable to load the file system codec ModuleNotFound。。
- mac /include/c++/v1/iterator:341:10: fatal error: '__debug' file not found #include <__debug>
- 编译安装PHP出现configure: error: mysql configure failed. Please check config.log的解决方法
- 编译安装PHP出现configure: error: MySQL configure failed. Please check config.log的解决方法