1. 程式人生 > >macOS Mojave install MySQL-python

macOS Mojave install MySQL-python

error:

cc -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/8.0.15/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.14-intel-2.7/_mysql.o
_mysql.c:44:10: fatal error: 'my_config.h' file not found
#include "my_config.h"
         ^~~~~~~~~~~~~
1 error generated.

 

solve:

brew install mysql-connector-c

download原始碼包解壓

裡面有個 site.cfg

connector = /usr/local/Cellar/mysql-connector-c/6.1.11 替換為mysql-connector-c的路徑

另外:如果沒有管理員沒有辦法加入到/usr/local目錄下

==> Pouring mysql-connector-c-6.1.11.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink include/big_endian.h
/usr/local/include is not writable.

You can try again using:
  brew link mysql-connector-c
==> Summary

假如你的虛擬python env叫做testenv

cd testenv下面

ln   /usr/local/Cellar/mysql-connector-c/6.1.11/include/* include/*

ln   /usr/local/Cellar/mysql-connector-c/6.1.11/lib/* lib/*

再次安裝,大功告成

MySQL-python 1.2.5 is already the active version in easy-install.pth

 

Python 2.7.10 (default, Feb 22 2019, 21:17:52)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>