一旦諦めてましたが、職場の大大大先輩のおかげでこの数日C/C++のコンパイルスキル上がったので再度トライ!
# まずは、自分でmysql−connector-c をダウンロードし、インストール
https://dev.mysql.com/downloads/connector/c/
# ここの詳細は割愛する, でもこんな感じ。 tar zxvf xxxx.tar.gz; cd mysql*; mkdir build; cd build; cmake ..; make; sudo make install
# mysql_config は/usr/local/mysql/bin/にインストールされるので適当にリンク貼る
ln -s /usr/local/mysql/bin/mysql_config /usr/local/bin/
% pip install mysql-python
Collecting mysql-python
Using cached MySQL-python-1.2.5.zip
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/private/var/folders/9j/12cqyk6x2s5dc22x2mnlpmmw0000gn/T/pip-build-Cf6eHO/mysql-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 53, in get_config
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
File "setup_posix.py", line 8, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
# 自分でzipダウンロードしトライするhttps://pypi.python.org/pypi/MySQL-python/1.2.5
% unzip MySQL-python-1.2.5.zip; cd MySQL-python*;
% python setup.py build
Traceback (most recent call last):
File "setup.py", line 17, in <module>
metadata, options = get_config()
File "./MySQL-python-1.2.5/setup_posix.py", line 53, in get_config
libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
File "./MySQL-python-1.2.5/setup_posix.py", line 8, in dequote
if s[0] in "\"'" and s[0] == s[-1]:
IndexError: string index out of range
# ここはPythonのバグ、文字列をチェックしていないので、以下の方法でFix
if s[0] in "\"'" and s[0] == s[-1]:
を
if s and s[0] in "\"'" and s[0] == s[-1]:
に変更。
# もう一回トライ
% python setup.py build
/usr/bin/clang -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -g build/temp.macosx-10.6-intel-2.7/_mysql.o -L/usr/local/mysql/lib -l -o build/lib.macosx-10.6-intel-2.7/_mysql.so
clang: error: no such file or directory: 'build/lib.macosx-10.6-intel-2.7/_mysql.so'
error: command '/usr/bin/clang' failed with exit status 1
# こんな楽だと思ったが、現実はそんなにあまくない!
# 内容確認したが.oは作られている、でも.soの作成に失敗
# じゃ、自分でコンパイルするか
clang -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.6-intel-2.7/_mysql.o -L/usr/local/mysql/lib -lmysqlclient -o build/lib.macosx-10.6-intel-2.7/_mysql.so
# -lmysqlclientがポイント, pythonはわざとリンクしない、動的に発見させる
# エラーなし、はいOK
# インストールすれば完成
% python setup.py install
...
Processing dependencies for MySQL-python==1.2.5
Finished processing dependencies for MySQL-python==1.2.5
% python
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 12:39:47)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _mysql
>>> import MySQLdb
>>> ^D
:)